Connecting to Jet 4.0/Access database

  • Thread starter Thread starter Peter Rabbit
  • Start date Start date
P

Peter Rabbit

My attempts to open a Jet database in CSharp .Net fail. I am trying the
following:
string cstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Documents and
Settings/.../Data/List.mdb;Connect Timeout=5";

OleDbConnection sdb = new OleDbConnection(cstr);

sdb.Open();

but the Open generates an OleDbException. Is there soemthing wrong with the
connection string?

Thanks
 
Typically, the error message will have more specifics: unauthorized user,
could not find file, etc. What message is in the exception?
 
¤ My attempts to open a Jet database in CSharp .Net fail. I am trying the
¤ following:
¤ string cstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Documents and
¤ Settings/.../Data/List.mdb;Connect Timeout=5";
¤
¤ OleDbConnection sdb = new OleDbConnection(cstr);
¤
¤ sdb.Open();
¤
¤ but the Open generates an OleDbException. Is there soemthing wrong with the
¤ connection string?

Yes, you need to escape the slash character in your database file path:

OleDbConnection objConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\\My
Documents\\db1.mdb");


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Thanks for your response. After enclosing the Open function in a 'try'
clause, the Exception object gave the message:
"Multiple-step OLE DB operation generated errors. Check each OLE DB status
value, if available. No work was done."

I don't know if that helps. "Each OLE DB status value" - where do I find
these values?
 
Sorry, the quote I gave was misleading. I had tried forward slashes. The
backslashes are in fact 'escaped' in the real version, and the problem is
the same.

Thanks
--
Peter Aspey
-------------------------------------------------------
email: replace 6 by p

Paul Clement said:
¤ My attempts to open a Jet database in CSharp .Net fail. I am trying the
¤ following:
¤ string cstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Documents and
¤ Settings/.../Data/List.mdb;Connect Timeout=5";
¤
¤ OleDbConnection sdb = new OleDbConnection(cstr);
¤
¤ sdb.Open();
¤
¤ but the Open generates an OleDbException. Is there soemthing wrong with the
¤ connection string?

Yes, you need to escape the slash character in your database file path:

OleDbConnection objConn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\\My
 
Open now works! I limited the arguments in the connection string to
'Provider' and 'Data Source' only (i.e. removed the 'Connect Timeout').
So don't waste any time on my last message!
Thanks again
 
¤ Sorry, the quote I gave was misleading. I had tried forward slashes. The
¤ backslashes are in fact 'escaped' in the real version, and the problem is
¤ the same.

Could you post the code with the exact connection string you are using.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
¤ Open now works! I limited the arguments in the connection string to
¤ 'Provider' and 'Data Source' only (i.e. removed the 'Connect Timeout').
¤ So don't waste any time on my last message!

In that case ignore my follow-up question.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top