error with MS Access

I am trying to open a connection to a MSAccess dataBase however, when i do i get this error - ex {"ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"} System.Data.Odbc.OdbcException

how do i get around this here is my code

string errlocal = "No DataBase Errors";

err = errlocal;

constring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\Francis Jackson\\My Documents\\Mentor.mdb";

OdbcConnection DBConstring = new OdbcConnection(constring);

try

{

// DBConstring.ConnectionString = constring;

DBConstring.Open();

sqlcmd = new OdbcCommand(sqlstring, DBConstring);

sqlcmd.Connection.Open();

result = (int)sqlcmd.ExecuteNonQuery();

sqlcmd.Connection.Close();

}

catch (OdbcException ex)

{

errlocal = ex.ToString();

}

}

Cisco



Answer this question

error with MS Access

  • jjoravec

    Because your connection string specified the OleDb provider, you have to use the OleDbConnection, OleDbCommand (and so on) classes.

  • Anusuya

    I suspect you are using a bad connection string. Try something like:

    @"Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\Documents and Settings\Francis Jackson\My Documents\Mentor.mdb;UID=;PWD=;"

    Please provide the username and password if appropriate.

    Even better, ditch ODBC. ;)
    HTH
    --mc


  • error with MS Access