IBM DB2 Database Connection String in C#

In this article, I have listed C# code snippets of connection string for IBM DB2 Database.


IBM DB2 Database Connection String in C#:

Connection String provide the required information to the driver that tells where to find the default connection information. Optionally, you are allowed to specify attribute=value pairs in the connection string to override the default values stored in the data source.

1. ODBC DSN ConnectionString

using System.Data.Odbc;
var conn = new OdbcConnection();
conn.ConnectionString = 
              "Dsn=DsnName;" + 
              "Uid=UserName;" + 
              "Pwd=Secret;"; 
conn.Open();

2. ODBC without DSN

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

3. OleDb – Microsoft Driver

using System.Data.OleDb;
var 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;"; 
conn.Open();

4. OleDb – IBM Driver

using System.Data.OleDb;
var conn = new OleDbConnection();
conn.ConnectionString = 
            "Driver=IBMDADB2;" + 
            "DataBase=DataBaseName;" + 
            "HostName=ServerName;" + 
            "Protocol=TCPIP;" + 
            "Port=PortNumber;" + 
            "Uid=UserName;" + 
            "Pwd=Secret;"; 
conn.Open();

5. OleDb – IBM Driver

using System.Data.OleDb;
var conn = new OleDbConnection();
conn.ConnectionString = 
            "Driver=IBMDADB2;" + 
            "DataBase=DataBaseName;" + 
            "HostName=ServerName;" + 
            "Protocol=TCPIP;" + 
            "Port=PortNumber;" + 
            "Uid=UserName;" + 
            "Pwd=Secret;"; 
conn.Open();

6. NET DataProvider from IBM

using IBM.Data.DB2;
var conn = new Db2Connection();
conn.ConnectionString = 
              "DataBase=DataBaseName;" + 
              "Uid=UserName;" + 
              "Pwd=Secret;" + 
conn.Open();

– Article ends here –

If you have any questions, please feel free to share your questions or comments on the comment box below.

Recommended:   Microsoft Sql Express Database Connection String in C#
Share this:
We will be happy to hear your thoughts

Leave a reply

Troubleshootyourself
Logo