HI WELCOME TO SIRIS

DB2 Connection Strings in Ado.Net

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.

Using ODBC

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

Using OLEDB

  1. // OleDb -- Microsoft Driver
  2. using System.Data.OleDb;
  3. OleDbConnection conn = new OleDbConnection();
  4. 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;";
  5. conn.Open();
  6. // OleDb -- IBM Driver
  7. using System.Data.OleDb;
  8. OleDbConnection conn = new OleDbConnection();
  9. conn.ConnectionString = "Driver=IBMDADB2; DataBase=DataBaseName; HostName=ServerName; Protocol=TCPIP; Port=PortNumber; Uid=UserName; Pwd=Secret;";
  10. conn.Open();

Using .Net DataProvider

  1. // .NET DataProvider from IBM
  2. using IBM.Data.DB2;
  3. Db2Connection conn = new Db2Connection();
  4. conn.ConnectionString = "DataBase=DataBaseName;Uid=UserName;Pwd=Secret";
  5. conn.Open();