I am using VS 2010 and C#. I want to connect to an MDB in C#. ’till now what I have done is as follows:
string strAccessConn = "Provider=Microsoft.ACE.OLEDB.4.0;Data Source=C:\\Databases\\"+DBname+".mdb";
DataSet myDataSet = new DataSet();
OleDbConnection myAccessConn = null;
try
{
myAccessConn = new OleDbConnection(strAccessConn);
OleDbCommand myAccessCommand = new OleDbCommand(Query, myAccessConn);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);
myAccessConn.Open();
myDataAdapter.Fill(myDataSet, "Table");
}
catch(Exception Ex)
{
MessageBox.Show(Ex.ToString());
}
finally
{
myAccessConn.Close();
}
The database returns the valid DataSet … thats not the problem for Access 2000 Database
However when I change the connection string to
string strAccessConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Databases\\"+DBname+".mdb";
for MSAccess2007 the database path is not found and an exception is generated although it exist. Am I missing any references?
Try changing your Access data file extension from
.mdbto.accdb:See connectionstrings.com for reference.