Microsoft Access Database Connection String in C#

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


Microsoft Access Database Connection String in C#:

ConnectionString 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

using System.Data.Odbc;
using System.Data.Odbc;
var conn = new OdbcConnection();
conn.ConnectionString = "Dsn=DsnName";
conn.Open();

2. ODBC – Standard Security

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

3. ODBC – Workgroup (System Database)

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

4. ODBC – Exclusive Use

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

5. OleDb with MS Jet – Standard Security

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

6. OleDb with MS Jet — Workgroup (System Database)

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

7. OleDb with MS Jet – With Password

using System.Data.SqlClient;
using System.Data.OleDb;
var conn = new OleDbConnection();
conn.ConnectionString = 
           "Provider=Microsoft.Jet.OLEDB.4.0;" + 
           "Data Source=c:\mypath\myDb.mdb;" + 
           "Database Password=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:   Namespace Alias Qualifier in C#
Share this:
We will be happy to hear your thoughts

Leave a reply

Troubleshootyourself
Logo