In the project, use C # To connect to DB2, and always use the class sqlhelp. If you know that this class can boast a database, you only need to make slight modifications to the config configuration, but it has never been used.
Today, we just need to connect to DB2. We have a good time trying to connect to DB2.
Recorded here:
With simple configuration, you can switch the database.
<! -- Sql2005 -->
< Add Name = "Connectionstring2" Connectionstring = "Server = 192.168.1.238; uid = sa; Pwd = sa; database = unified messaging platform; Connection Reset = true; timeout = 300"
Providername = "System. Data. sqlclient" />
<! -- DB2 -->
< Add Name = "Connectionstring" Connectionstring = "Provider = ibmdadb2.db2copy1; database = bypdc; hostname = 192.168.1.11; Protocol = TCPIP; Port = 50000; uid = wmes; Pwd = w123456 ;"
Providername = "System. Data. oledb" />
Bytes ---------------------------------------------------------------------------------------------------------------
According to the above connection settings, the Select database can be used normally, but some problems may occur when updating parameters.
1 Public Static StringIm_recent_contact_td _ add= "Insert into values (user_id, contact_id, contact_name, update_time, create_time, last_modi_time) value (@ user_id, @ contact_id, @ contact_name, @ update_time, @ create_time, @ last_modi_time)";
The following statements may cause problems:
1 Public Static Bool Add ( String Guid, String Key, String Catalog, String DESC, String Text)
2 {
3 Dbparameter [] pars;
4 Pars = New Dbparameter [ 5 ];
5
6 Pars [ 0 ] = Dao. createparameter ( " @ ID " , Dbtype. String, guid );
7 Pars [ 1 ] = Dao. createparameter ( " @ Catalog " , Dbtype. String, catalog );
8 Pars [ 2 ] = Dao. createparameter ( " @ Config_key " , Dbtype. String, key );
9 Pars [ 3 ] = Dao. createparameter ( " @ Text " , Dbtype. String, text );
10 Pars [ 4 ] = Dao. createparameter ( " @ Description " , Dbtype. String, DESC );
11 Return Dao. executecommand (SQL. sysconfig _ add, pars) > 0 ;
}
SQL parameterization @ xxx changed to use? Replace
Public Static String Sysconfig _ add = @" Insert " + Schemaname + " Im_sys_config_tb (ID, catalog, config_key, text, description) values (?,?,?,?,?) " ;
When assigning values, the order must be consistent, and spaces are not allowed between fields in SQL statements.
The Windows client connects to the DB2 tool. toad for DB2 and also has a vs plug-in.