Connecting to Jet 4.0/Access database

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
 
M

Marina

Typically, the error message will have more specifics: unauthorized user,
could not find file, etc. What message is in the exception?
 
P

Paul Clement

¤ 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)
 
P

Peter Rabbit

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?
 
P

Peter Rabbit

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
 
P

Peter Rabbit

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
 
P

Paul Clement

¤ 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)
 
P

Paul Clement

¤ 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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top