Use sqlhelp. CS to connect to DB2

Source: Internet
Author: User
Tags connection reset

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.