|
Dear, Sir
I will develop an application that automatic check what update on database on the Web Server.
Please give me an idea and overview about it. To get what update via Internet I should use what classs.
I ever create database application, but I never create application that connect to the internet.
And I think I should use thread in this application. Is.... correct?
Thank You.
Sorry for bad English.
;);P ((
|
|
|
|
|
You need to read about ADO.NET. Disconnected data sources is the main area.
HTH
Luke
PS: Never appologise for your english (most of us "english" do not speak it very well and the majority cannot even speak another language including me
|
|
|
|
|
As Jinwah was getting at, see the System.Data.DataSet class documentation in the .NET Framework SDK, as well as System.Data.Common.DbDataAdapter - specifically, one of its derived classes depending on what database you're accessing (like System.Data.SqlClient.SqlDataAdapter for a SQL Server database).
You give the DbDataAdapter the appropriate SELECT, INSERT, UPDATE, and DELETE commands (it has properties for each), which you can either use the DataAdapter designer in VS.NET or a CommandBuilder to generate, or type them yourself but generating an example to get an idea might be a good idea.
Then, whenever you update, remove, or insert information in the DataSet , you call DbDataAdapter.Update(DataSet) which will use the change type information for each DataRow and will call the appropriate DbCommand on the DbDataAdapter . There are several examples of this on the CodeProject web site, as well as examples in the .NET Framework SDK.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have the following code:
<br />
<br />
try<br />
{<br />
string ConnString;<br />
ConnString="Provider=SQLOLEDB;";<br />
ConnString+="data source=127.0.0.1;";<br />
ConnString+="initial catalog=AutoConvert;";<br />
ConnString+="password=password;";<br />
ConnString+="persist security info=False;";<br />
ConnString+="user id=sa;";<br />
OleDbConnection dbConn = new OleDbConnection(ConnString);<br />
dbConn.Open();<br />
<br />
FileStream fs = File.Open("c:\\temp\\output.dat",FileMode.Open);<br />
BinaryReader BR = new BinaryReader(fs);<br />
byte [] BLOB=BR.ReadBytes(Convert.ToInt32(fs.Length));<br />
DataBase.InsertBLOB(dbConn,"Documents","BatchName","1234567",true,"Document",BLOB);<br />
dbConn.Close();<br />
<br />
}<br />
catch(Exception Err)<br />
{<br />
Console.WriteLine(Err.Message);<br />
}<br />
<br />
<br />
<br />
<br />
static public void InsertBLOB(OleDbConnection db,string Table,string LookUpField,string LookUpData,bool IsLookUpString,string BLOBField,byte [] BLOB)<br />
{<br />
try<br />
{<br />
string Command;<br />
if(IsLookUpString)<br />
Command= String.Format("UPDATE {0} SET {1}=@{1} WHERE({2}='{3}')",<br />
Table,BLOBField,LookUpField,LookUpData);<br />
else<br />
Command= String.Format("UPDATE {0} SET {1}=@{1} WHERE({2}={3})",<br />
Table,BLOBField,LookUpField,LookUpData);<br />
OleDbCommand addEmp = new OleDbCommand(Command, db); <br />
addEmp.Parameters.Add("@"+BLOBField,BLOB);<br />
addEmp.ExecuteNonQuery();<br />
}<br />
catch(Exception Err)<br />
{<br />
throw new Exception(Err.Message);<br />
}<br />
}<br />
addEmp.ExecuteNonQuery throws an exception witht he message:
"You must define @Document"
I copied the code almost directly from MSDN, but I can't get it to work...Any ideas ?
Oh and in my AutoConvert Catalog I have the table Documents with an image field of length 16 called Document.
|
|
|
|
|
First of all, if you're connecting to a SQL Server, you should be using the class in System.Data.SqlClient . These classes - including the SqlParameter (as opposed to OleDbParameter ) are optimized for SQL Server.
Finally, you must define the type of your SqlParameter like so:
SqlParameter parm = addEmp.Parameters.Add("@" + BLOBField, SqlDbType.Image;
parm.Value = BLOB; See http://msdn.microsoft.com/library/en-us/cpguide/html/cpconwritingblobvaluestodatabase.asp[^] for an example.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the help as always Heath, I thought SqlConnection and OleDbConnection class were interchangable...
|
|
|
|
|
You can use the System.Data.OleDb classes to access SQL Server, but they are not optimized for any one database - they just use the OLE DB driver using only the common abstract implementations. As far as mixing these two collections of classes together, that's not really supported because most methods in the derived classes take specific types indicitive of their namespace (like a SqlCommand can take a SqlConnection , not a generic DbConnection ).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I've been a VC++ programmer for about 4 years now and I'm learning C#, you been a great help thus far Heath...thanks
|
|
|
|
|
A solution that I'm developing has a server and multiple clients. The clients access Client-Activated object on the remoting server. What would be the best way of keeping track of the connections?
I have a SQL server on the same machine and I'm thinking about doing it like this: on init - add an entry in the connection table. when the object is disposed it will remove itself from the table. However, there are a few problems.
+ if the client crashes -> when the lease runs out the connection will be unregistered. right?
+ What about if the server crashes - I'll just clean up the connection table on startup.
Does anyone have any suggestions?
|
|
|
|
|
Your SQL-Server solution works, but there is an easier way to tracking your clients (I think):
Create an ArrayList and add each ClientObject by creation.
Use delegates to remove ClientObjects, when there lease is running out.
If the server crashes, the ArrayList will be removed automatically
|
|
|
|
|
Actually, this is not so good but your solution to use a lease is what I was going to recommend anyway. I originally recommend using a database as we do for our app (which is driven by a SQL Server anyway) because if your remoting object goes down for some reason, your list is lost. The database (in our case, which is replicated and stored on a RAID array) will persist this information so that when the remoting object comes back up, it can grab the information and return to its original state.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
As I hinted at before, implement ILease and return that in an override for GetLifetimeService on your remoting object. If a sponser cannot be contacted or has not renewed the time on the lease, you remove the row from the RDBMS for that sponsor (a client). In an internal remoting application, your lease can ping the sponsers to determine if they still exist. If you expose your remoting object on IIS (which automatically gets exposed as a Web Service, thus using HTTP which is one-way), you'll just have to wait until the sponsor does not renew their lease and remove the row.
If the remoting object (the server) crashes, this really isn't a problem. As long as the database is still up and running, the remoting object will grab the existing information (this is the reason I mentioned you should persist connection information in a database or something) and restore its state. Clients can't really connect why the remoting object is down, so you don't have to worry about new information. Now if the server(s) that has/have both your remoting object and the database go down, the scenario isn't much different from before. Just use transacted statements to increment and decrements your client connections table and they will be logged so that they can be completed in such a case.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Actually, this is for a different but similar project.
I had everything covered the only thing was : If the activated object crashes and the client app never decides to re-activate the object. The information will remain on the server, and the admin app on the server will read the entry in the database as a live connection.
|
|
|
|
|
That would be a problem, then. I guess the only thing you could do in such a case is to prevent the admin application from worrying about what's in that table and instead get the remoting object and this admin app to interact instead of using a table as a sort of intermediary.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Does anyone know how to MODIFY the value of a custom attribute associated with a class property at runtime?
I havn't been able to find a single example of this on the net.
Thanks Heaps,
Patrick.
|
|
|
|
|
You can't modify attributes at runtime. You can, however, use an ICustomTypeDescriptor to return an array of attributes that you can create at runtime (note, this interface is only used by certain classes like the TypeDescriptor in System.ComponentModel ).
See the documentation for ICustomTypeDescriptor.GetAttributes for more information.
If you use reflection instead of a TypeDescriptor to get attributes, you won't be able to change anything unless you programmatically create an attribute and add it to your array/list/collection.
Finally, if this is a custom attribute, you can give the attribute's property a set accessor as well, but this is to change only a property. This is highly NOT recommend, though, because attributes are meta-data that describe classes, etc. The attributes in the base class library don't allow such changes. If you need to modify values like this, you should consider a abstract or virtual property for a particular type that child classes can override, or using an interface for a good polymorphic design.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi There,
Yes, besides being a great music it's the situation I'm in right now.
I've searched and searched and I cannot find what I want, I'm starting to think that it's not possible.
I've developed a service using C#, and used one of the great advantages of .NET, the possibility to easily install a service, I've done everything I wanted, except for this:
Is it possible to set the name of the service during installation?
I must/want to give this option so that the user can install several instances of that service each with a different name. (Gateway I,Gateway II, etc).
If this is impossible what are the alternatives?
Thanks for all the replies,
Luis Pinho
|
|
|
|
|
See ServiceInstaller and ServiceProcessInstaller . The documentation for these two classes in the .NET Framework SDK also include samples.
Basically, you derive from Installer to create your own installer then add an instance of each of the aforementioned classes according to the documentation.
You can use the installutil.exe utility that is installed with the .NET Framework or include the assembly that includes the installer class in a Windows Installer setup project in VS.NET as a Custom Action.
If you want to set anything during installation, you'll have to use a command-line switch. You can find more information about this in the documentation for the Installer.Context property. You use some code like the following in your derived Installer class to get parameters passed to it from installutil.exe or from Windows Installer:
string value = Context.Parameters["SvcName"]; If you want to use this in an MSI package (Windows Installer), you can pass the command-line option based on an MSI database property that can be set by msiexec.exe when installing the package. For more information about that, see a previous thread I replied to: http://www.codeproject.com/script/comments/forums.asp?msg=711576&forumid=1649&XtraIDs=1649&searchkw=custom+action+windows+installer&sd=10%2F17%2F2003&ed=1%2F15%2F2004#xx711576xx[^].
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi...i need what my subjust states, and have no idea how to get their...Short of creating my own listview from scratch...does anyone know any solution to this? (c#)
|
|
|
|
|
dang...it doulbe posted and i cant delete cause of some forum bug saying i used a differant account to make this lol.
anyhoo when i said sort, i mean scroll
|
|
|
|
|
Hi...i need what my subjust states, and have no idea how to get their...Short of creating my own listview from scratch...does anyone know any solution to this? (c#)
|
|
|
|
|
The first thing is to understand that the ListView class in .NET encapsulates the List-View common control in Windows, as do most controls in the System.Windows.Forms namespace, so doing things like this will typically required that you extend ListView , override WndProc , and handle notification messages. Some Windows programming background will be helpful. You'll also want to know how to P/Invoke native methods. You can find more information in the documentation for the DllImportAttribute in the .NET Framework SDK.
You'll have to handle the drawing of each subitem by handling the NM_CUSTOMDRAW notification message. That will give you a struct (which you'll have to create, namely the NMLVCUSTOMDRAW struct). From information in that you can adjust the starting location of your text (though you'll have to draw it yourself, though that's not hard) and then paint the icon you want next to it. You'll have to figure out how to store that image information, though, be it an index into an ImageList or an Image itself. You could extend ListViewSubItem although you'll have to worry about casting each time.
Note that this may sound like a lot of work (and I'll admit it's not trivial) but it sure beats making your own list view control from scratch! There's a heck of a lot more to worry about than this. In the grand scheme of things, this approach is easy.
If you reply to this, I can send you some old source that shows some examples of owner-drawing. Though not specific to your requirements, it should give you some insight.
Again, be sure to read about the list-view common control at http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/listview/reflist.asp[^] and read about P/Invoking at http://msdn.microsoft.com/library/en-us/cpguide/html/cpconconsumingunmanageddllfunctions.asp[^]. Again, some Windows programming experience will be helpful.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Wow that owner-drawing stuff sounds tasty...Be most appreaciated :P
|
|
|
|
|
Hi there,
I have this little problem which is of pure cosmetic nature, so it doesn't really affect the application, but it would be something I'd really like to have. I searched around and couldn't find a solution for this anywhere, so I hope somebody in here knows the trick. The problem does also apply to any other .NET application, but since my application is written in C#, I post it here first:
My appplication has a nice application icon and opens several windows, which also all have this application icon. Everything looks fine in the windows taskbar, until the moment when the taskbar grouping function of WinXP kicks in. Then the group icon for my application suddenly is the default empty application icon, and the group button itself doesn't have any text, but just states the number of windows grouped, for example "3".
When I click on the group button, every item in the list has the nice application icon, but it seems that the group icon comes from somewhere else, as well as the group button text. Since other applications still have their icon even when the windows are grouped, this property must be able to set somewhere.
I read in a newsgroup that the group icon comes from SystemIcons.Application, which in fact is the empty default windows icon that I see, but this property is read-only, so there is no way for me to confirm that this icon is really used, nor can I change it to my application icon.
In case it is still not clear what I mean to the following to reproduce the problem: Open a new .NET project (C# or VB doesn't matter) and add a second dialog, then add a function in your main dialog that opens up the second dialog when clicking a button or something like that. Edit the App.ico resource so that the icon looks different and make both your windows use this file as the application icon. Now execute the application and press that button that executes your function to open more windows until the taskbar is full and WinXP groups the icons. Then you should be able to see the effect.
In case it is still not clear, I can also post a screenshot, but for the moment I'll just hope that someone is able to understand what I mean.
Any ideas?
Thanks,
Sascha
|
|
|
|
|
Set the static property Application.SafeTopLevelCaptionFormat for the group text. As far as the icon goes, I'm frankly surprised this isn't working correctly since Windows should be using the top-level form's icon. The only thing I can think of is to make sure you're using the Application.Run static method to launch your main form.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|