Search_Blog



 

View Blog

Aug 8

Written by: IOTAP ::-- DotNet Team
8/8/2008 2:16 PM

Versions of Microsoft Access prior to 2007 stored the database with extension .mdb. In Access 2007 this is changed to .accdb. This blog explains how to connect version 2007 of Access database from .Net.

 

Typical connection string for connecting to previous version of access database is

“Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;”

But when we try to apply the same to Access 2007 database as below

OleDbConnection CON = new OleDbConnection();

OleDbCommand CMD = new OleDbCommand("Select ProductName from dbo_products ");

CON.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\IOTAP\Projects\DBMigrate\MyDatabase.accdb;";

CON.Open();

An oledbexcption would be thrown with the message "Unrecognized database format 'D:\\IOTAP\\Projects\\DBMigrate\\Mydatabase.accdb'."

This is because Microsoft has replaced jet database engine with a new database engine named ACE (Access Control Entry) in Access 2007. You can get more details about ACE here http://blogs.msdn.com/access/archive/2005/10/13/480870.aspx

The new connection string for Access 2007 database would be of the syntax

“Provider=Microsoft.ACE.OLEDB.12.0; Data source=;”

For example

OleDbConnection CON = new OleDbConnection();

OleDbCommand CMD = new OleDbCommand("Select ProductName from dbo_products ");

CON.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=D:\IOTAP\Projects\DBMigrate\MyDatabase.accdb;";

CON.Open();

You can find variants of Access 2007 connection strings from http://www.connectionstrings.com/?carrier=access2007

Cheers  

Tags:

Your name:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment    Cancel