Ram
Ram

Reputation: 45

How to connect Ms access 2010 (.accdb ) database with odbc driver

Can any one tell how to connect Ms access 2010 (.accdb ) database with odbc driver in c# and .NET 4.0

I tried

string connetionString = ("Driver={Microsoft Access Driver(*.mdb*.accdb)};DBQ=C:\\Users\\Administrator\\Desktop\\New folder\\MatchDetails.accdb;");

OdbcConnection myConnection = new OdbcConnection(connetionString);

try
{                   
    myConnection.Open();
    MessageBox.Show("Connection Open ! ");
    myConnection.Close();
}
catch (Exception ex)
{
    MessageBox.Show("Can not open connection ! ");
}

throwing this Exception

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified exception

Upvotes: 2

Views: 22260

Answers (2)

ucorpor
ucorpor

Reputation: 11

I see a two typos in driver name:

  1. There is no space before the brackets
  2. There is no comma inside the brackets

Correct connection string:

string connectionString = ("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\\Users\\Administrator\\Desktop\\New folder\\MatchDetails.accdb;");

Upvotes: 0

D Stanley
D Stanley

Reputation: 152501

You have a typo in your connection string:

string connectionString = ("Driver={Microsoft Access Driver(*.mdb, *.accdb)};DBQ=C:\\Users\\Administrator\\Desktop\\New folder\\MatchDetails.accdb;");

(note the comma in the Driver name)

Upvotes: 4

Related Questions