Monday, 24 September 2012

Excel Sheet Database Connectionstrings | Text File Database Connectionstrings | Microsoft Access Database



Excel Sheet Database
// ODBC DSN

using System.Data.Odbc;

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



// ODBC without DSN

using System.Data.Odbc;

OdbcConnection conn = new OdbcConnection();
conn.ConnectionString =
       "Driver={Microsoft Excel Driver (*.xls)};" +
       "Driverid=790;" +
       "Dbq=C:\MyPath\SpreadSheet.xls;" +
       "DefaultDir=C:\MyPath;";
conn.Open();



// OleDb with MS Jet

using System.Data.OleDb;

OleDbConnection conn = new OleDbConnection();
conn.ConnectionString =
    "Driver=Microsoft.Jet.OLEDB.4.0;" +
    "Data Source=C:\MyPath\SpreadSheet.xls;" +
   @"Extended Properties=""Excel 8.0;HDR=Yes""";
conn.Open();



Text File Database
// ODBC DSN

using System.Data.Odbc;

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



// ODBC without DSN

using System.Data.Odbc;

OdbcConnection conn = new OdbcConnection();
conn.ConnectionString =
 "Driver={Microsoft Text Driver (*.txt; *.csv)};" +
 "Dbq=C:\MyPath\;" +
 "Extensions=asc,csv,tab,txt;";
conn.Open();

// Use: sql = "Select * From MyTextFile.txt"



// OleDb with MS Jet

using System.Data.OleDb;

OleDbConnection conn = new OleDbConnection();
conn.ConnectionString =
      "Driver=Microsoft.Jet.OLEDB.4.0;" +
      "Data Source=C:\MyPath\;" +
      "Extended Properties=" +
        @"""text;HDR=Yes;FMT=Delimited""";
conn.Open();

// Use: sql = "Select * From MyTextFile.txt"


Microsoft Access Database

// ODBC DSN

using System.Data.Odbc;

OdbcConnection conn = new OdbcConnection();
conn.ConnectionString = "Dsn=DsnName";
conn.Open();



// ODBC -- Standard Security

using System.Data.Odbc;

OdbcConnection conn = new OdbcConnection();
conn.ConnectionString =
    "Driver={Microsoft Access Driver (*.mdb)};" +
    "Dbq=c:\myPath\myDb.mdb;" +
    "Uid=Admin;Pwd=;";
conn.Open();



// ODBC -- Workgroup (System Database)

using System.Data.Odbc;

OdbcConnection conn = new OdbcConnection();
conn.ConnectionString =
    "Driver={Microsoft Access Driver (*.mdb)};" +
    "Dbq=c:\myPath\myDb.mdb;" +
    "SystemDb=c:\myPath\myDb.mdw;";
conn.Open();

// ODBC -- Exclusive Use

using System.Data.Odbc;

OdbcConnection conn = new OdbcConnection();
conn.ConnectionString =
     "Driver={Microsoft Access Driver (*.mdb)};" +
     "Dbq=c:\myPath\myDb.mdb;" +
     "Exclusive=1;";
     "Uid=Admin;Pwd=;";
conn.Open();

// OleDb with MS Jet -- Standard Security

using System.Data.OleDb;

OleDbConnection conn = new OleDbConnection();
conn.ConnectionString =
           "Provider=Microsoft.Jet.OLEDB.4.0;" +
           "Data Source=c:\mypath\myDb.mdb;" +
           "User id=admin;" +
           "Password=";
conn.Open();




// OleDb with MS Jet -- Workgroup (System Database)

using System.Data.OleDb;

OleDbConnection conn = new OleDbConnection();
conn.ConnectionString =
           "Provider=Microsoft.Jet.OLEDB.4.0;" +
           "Data Source=c:\mypath\myDb.mdb;" +
           "System Database=c:\mypath\myDb.mdw;";
conn.Open();



// OleDb with MS Jet -- With Password

using System.Data.OleDb;

OleDbConnection conn = new OleDbConnection();
conn.ConnectionString =
           "Provider=Microsoft.Jet.OLEDB.4.0;" +
           "Data Source=c:\mypath\myDb.mdb;" +
           "Database Password=Secret;"
conn.Open();

No comments :