Wednesday, August 15, 2012

Connection Strings for Oracle with connection of C#!

Do you have a hard time remembering database connection strings?  You are not alone!  Here is an easy-to-use reference of connection strings for Oracle!


// ODBC DSN

using System.Data.Odbc;

OdbcConnection conn = new OdbcConnection();
conn.ConnectionString =
              "Dsn=DsnName;" +
              "Uid=UserName;" +
              "Pwd=Secret;";
conn.Open();



// ODBC -- New Microsoft Driver

using System.Data.Odbc;

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



// ODBC -- Old Microsoft Driver

using System.Data.Odbc;

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



// ODBC -- Oracle Driver

using System.Data.Odbc;

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




// OleDb -- Microsoft Driver

using System.Data.OleDb;

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




// OleDb -- Oracle Driver -- Standard Connection

using System.Data.OleDb;

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




// OleDb -- Oracle Driver -- Trusted Connection

using System.Data.OleDb;

OleDbConnection conn = new OleDbConnection();
conn.ConnectionString =
              "Driver=OraOLEDB.Oracle;" +
              "Data Source=ServerName;" +
              "OSAuthent=1;";
conn.Open();

// or

using System.Data.OleDb;

OleDbConnection conn = new OleDbConnection();
conn.ConnectionString =
              "Driver=OraOLEDB.Oracle;" +
              "Data Source=ServerName;" +
              "User id=/" +
              "Password=;";
conn.Open();



// .NET DataProvider from Microsoft
// -- Standard Connection

using System.Data.OracleClient;

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



// .NET DataProvider from Microsoft
// -- Trusted Connection

using System.Data.OracleClient;

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




// .NET DataProvider from Oracle
// -- Standard Connection

using Oracle.DataAccess.Client;

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




// .NET DataProvider from Oracle
// -- Trusted Connection

using Oracle.DataAccess.Client;

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

No comments: