ORACLE Database Connection String in C#

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


Oracle 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;
using System.Data.Odbc;
var conn = new OdbcConnection();
conn.ConnectionString = 
              "Dsn=DsnName;" + 
              "Uid=UserName;" + 
              "Pwd=Secret;"; 
conn.Open();

2. ODBC – New Microsoft Driver

using System.Data.Odbc;
var conn = new OdbcConnection();
conn.ConnectionString = 
           "Driver={Microsoft ODBC for Oracle};" + 
           "Server=OracleServer.world;" + 
           "Uid=UserName;" + 
           "Pwd=Secret;"; 
conn.Open();

3. ODBC – Old Microsoft Driver

using System.Data.Odbc;
var conn = new OdbcConnection();
conn.ConnectionString = 
    "Driver={Microsoft ODBC Driver for Oracle};" + 
    "ConnectString=OracleServer.world;" + 
    "Uid=UserName;" + 
    "Pwd=Secret;"; 
conn.Open();

4. ODBC – Oracle Driver

using System.Data.Odbc;
var conn = new OdbcConnection();
conn.ConnectionString = 
    "Driver={Oracle ODBC Driver};" + 
    "Dbq=myDataBase;" + // define in tsnames.ora
    "Uid=UserName;" + 
    "Pwd=Secret;"; 
conn.Open();

5. OleDb – Microsoft Driver

using System.Data.OleDb;
var conn = new OleDbConnection();
conn.ConnectionString = 
              "Driver=MSDAORA;" + 
              "Data Source=ServerName;" + 
              "User id=UserName;" + 
              "Password=Secret;"; 
conn.Open();

6. OleDb – Oracle Driver with Standard Connection

using System.Data.OleDb;
var conn = new OleDbConnection();
conn.ConnectionString = 
              "Driver=OraOLEDB.Oracle;" + 
              "Data Source=ServerName;" + 
              "User id=UserName;" + 
              "Password=Secret;"; 
conn.Open();

7. OleDb – Oracle Driver with Trusted Connection

using System.Data.OleDb;
var conn = new OleDbConnection();
conn.ConnectionString = 
              "Driver=OraOLEDB.Oracle;" + 
              "Data Source=ServerName;" + 
              "OSAuthent=1;";
conn.Open();
// or 
using System.Data.OleDb;
var conn = new OleDbConnection();
conn.ConnectionString = 
              "Driver=OraOLEDB.Oracle;" + 
              "Data Source=ServerName;" + 
              "User id=/" + 
              "Password=;"; 
conn.Open();

8. .NET DataProvider from Microsoft with Standard Connection

using System.Data.OracleClient;
var conn = new OracleConnection();
conn.ConnectionString = 
              "Data Source=ServerName;" + 
              "User id=UserName;"; 
              "Password=Secret;"; 
conn.Open();

9. .NET DataProvider from Microsoft with Trusted Connection

using System.Data.OracleClient;
var conn = new OracleConnection();
conn.ConnectionString = 
              "Data Source=Servername;" + 
              "Integrated Security=Yes;"; 
conn.Open();

10. .NET DataProvider from Oracle with Standard Connection

using Oracle.DataAccess.Client;
var conn = new OracleConnection();
conn.ConnectionString = 
              "Data Source=ServerName;" + 
              "User id=UserName;"; 
              "Password=Secret;"; 
conn.Open();

11. .NET DataProvider from Oracle with Trusted Connection

using Oracle.DataAccess.Client;
var conn = new OracleConnection();
conn.ConnectionString = 
              "Data Source=Servername;" + 
              "Integrated Security=Yes;"; 
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:   Windows Service in C# | Start, Stop, Pause, Resume, Restart code
Share this:
We will be happy to hear your thoughts

Leave a reply

Troubleshootyourself
Logo