HI WELCOME TO SIRIS

Oracle Connection Strings in Ado.Net

Oracle is most used database in the world. In Ado.net to make connection to Oracle we have multiple options. For this purpose we have different connection string to connect to the Oracle. Basically it is not easy to remember different database connection strings in Ado.Net. So I am sharing some connection strings to connect to the Oracle database using different drivers.

Using ODBC

  1. // ODBC -- New Microsoft Driver
  2. using System.Data.Odbc;
  3. OdbcConnection conn = new OdbcConnection();
  4. conn.ConnectionString = "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=UserName;Pwd=Secret;";
  5. conn.Open();
  6. // ODBC -- Oracle Driver
  7. using System.Data.Odbc;
  8. OdbcConnection conn = new OdbcConnection();
  9. conn.ConnectionString = "Driver={Oracle ODBC Driver};Dbq=myDataBase;Uid=UserName;Pwd=Secret;";
  10. conn.Open();

Using OLEDB

  1. // OleDb -- Oracle Driver -- Standard Connection
  2. using System.Data.OleDb;
  3. OleDbConnection conn = new OleDbConnection();
  4. conn.ConnectionString = "Driver=OraOLEDB.Oracle;Data Source=ServerName;User id=UserName;Password=Secret;";
  5. conn.Open();
  6. // OleDb -- Oracle Driver -- Trusted Connection
  7. using System.Data.OleDb;
  8. OleDbConnection conn = new OleDbConnection();
  9. conn.ConnectionString = "Driver=OraOLEDB.Oracle;Data Source=ServerName;OSAuthent=1;";
  10. conn.Open();
  11. // or
  12. using System.Data.OleDb;
  13. OleDbConnection conn = new OleDbConnection();
  14. conn.ConnectionString = "Driver=OraOLEDB.Oracle;Data Source=ServerName;User id=admin;Password=pwd";
  15. conn.Open();