Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I'm learning ADO.NET and have been stuck for DAYS trying to get a connection string for a plain, vanilla .mdb database. I've been trying potential connection strings and permutations but NOTHING works; the database connection is never opened.

The ODBC Data Source Administrator lists the driver as: "Driver do Microsoft Access (*.mdb)". Another application can successfully open this database, so I know my system is capable of it.

Can anyone suggest a SIMPLE connection string that will work?

What I have tried:

Tried strings from connectionstrings.com. Tried articles that discussed connection strings.
Posted
Updated 25-Aug-18 12:28pm

1 solution

That should be an older style (Access 2003 and older) database. It normally uses the JET engine, not ACE, though ACE may still be able to open it though.
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=path to database.mdb;
or
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=path to database.mdb;
Of course, you'll need the Access runtime or the appropriate version Office installed to open it, even from your own code, on every machine that's going to use the database.

For JET, it's Access 2003 and below. For ACE, it's any version of Access above 2003.

EDIT:
Oh, and the .MDB file MUST be in a folder the user has read and write permissions to. That does NOT include anything under Program Files.
 
Share this answer
 
v2
Comments
Alan Balkany 25-Aug-18 18:53pm    
Thanks Dave. Tried it and got: "System.Data.Odbc.OdbcException: 'ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified'"

The code:

IDbConnection myConn = new OdbcConnection(GetConnectionString ());
myConn.Open();

The error happens on the Open() call. I'm using your connection string like this:

return @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\ps\Data\Database File\xtreme.mdb;";

It happens with both connection strings. What am I doing wrong?
Dave Kreskowiak 25-Aug-18 18:59pm    
Ummm...you're using ODBC, not OLEDB. You can't use an OLEDB provider with ODBC.

Change the ODBC stuff to the OLEDB versions:
string connString = GetConnectionString();
OleDbConnection conn = new OleDbConnection(connString);   // DON'T combine statements together. It make debugging code harder.
conn.Open();
Alan Balkany 25-Aug-18 19:05pm    
That did it! Thanks Dave! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900