DB2 Connection Strings in Ado.Net

Shailendra Chauhan  Print   1 min read  
14 Feb 2012
14 Nov 2018

DB2 database is most useful RDBMS developed by IBM. Basically it is not easy to remember different database connection strings in Ado.Net. In Ado.net to make connection to DB2 we have multiple options. We have different connection string to connect to the DB2 database. So I am sharing some connection strings to connect to the DB2 database using different drivers. Also, you can raed our article for MySql Connection Strings in Ado.Net

Using ODBC

 // ODBC without DSN
using System.Data.Odbc;
OdbcConnection conn = new OdbcConnection();
conn.ConnectionString = "Driver={IBM DB2 ODBC DRIVER};DataBase=DataBaseName; HostName=ServerName; Protocol=TCPIP;Port=PortNumber;Uid=UserName;Pwd=Secret"; 


 // OleDb -- Microsoft Driver
using System.Data.OleDb;
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Driver=DB2OLEDB; Network Transport Library=TCPIP; Network Address=xxx.xxx.xxx.xxx; Package Collection=CollectionName; Initial Catalog=DataBaseName; User id=UserName; Password=Secret;"; 
// OleDb -- IBM Driver
using System.Data.OleDb;
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Driver=IBMDADB2; DataBase=DataBaseName; HostName=ServerName; Protocol=TCPIP; Port=PortNumber; Uid=UserName; Pwd=Secret;"; 

Using .Net DataProvider

 // .NET DataProvider from IBM 
using IBM.Data.DB2;
Db2Connection conn = new Db2Connection();
conn.ConnectionString = "DataBase=DataBaseName;Uid=UserName;Pwd=Secret";
Share Article

Take our free skill tests to evaluate your skill!

In less than 5 minutes, with our skill test, you can identify your knowledge gaps and strengths.

Learn to Crack Your Technical Interview

Training Schedules
+91 9999123502
Accept cookies and close this message