Connecting to DB2 database in the DOT NET Framework

Source: Internet
Author: User
Tags db2 dot net dot net framework

1. Install and register the DB2 dot NET Data provider driver on the machine where the dot NET Framework is already installed

2. Then introduce the Uing System.Data.Common assembly to the DOT NET Framework's namespaces

3. Start the database operation

DbProviderFactory factory = Dbproviderfactories.getfactory ("IBM.") Data.db2 ");
DbConnection con = factory. CreateConnection ();
Dbconnectionstringbuilder SB = Factory. Createconnectionstringbuilder ();
Sb. ConnectionString = "UID=ZHANGKB;PWD=ANDY,./8; Server=192.168.0.11:50000;database=issue ";
Con. ConnectionString =SB. ConnectionString;
Con. Open ();
DbCommand DBC = con. CreateCommand ();
Dbc.commandtext = "Select Bank_name from ISSUE. S_bank WHERE bank_no= ' 1101 ';
string s = dbc. ExecuteScalar (). ToString ();
Con. Close ();
Response.Write (s);

Note: Here is an explanation of the above code:

DbProviderFactory The purpose of this sentence is to declare that my next operation is based on IBM.DATA.DB2

The key word is the connection string of the database: SB. Connetiongstring= "UID=ZHANGKB;PWD=ANDY,./8; Server=192.168.0.11:50000;database=issue ";

UID is the user name of the DB2 database, PWD is the password corresponding to the DB2 database username, the server is to specify the IP address of the DB2 database you want to connect to and the corresponding port number, and the port number of the DB2 database under Windows is generally 50000. In other cases, such as Unix,linux, the 60000.database is the name of the database you are saying you want to access. The rest of the operation of their own look at the understanding.

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.