0

I have SQL Server 2019 and MS Access installed. Our customer sent us 2 files - .MDB and .MDW. Also, the .MDB file is protected by a password. So when I open the .MDB file in Access, I need to change the workspace from the .MDW file and write a password.

As for now, I work on some C# app that should connect to that .MDB file and export some data from some tables. But when I try to read the data I get an error.

I don't have an experience with Access API, so I use standard C# OleDd objects to connect (I don't know if it's the correct way).

Here is a sample of my connection code:

string pathToMdb = "D:\test.mdb";
string pathToMdw = "D:\test.mdw";
string userName = "JohnAdmin";
string userPassword = "11111111";

string connectionString = $"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={pathToMdb};Jet OLEDB:System Database={pathToMdw};User ID={userLogin};Password={userPassword};";

OleDbConnection connection = new OleDbConnection(connectionString);

In this case, I have a successful connection. And, for example, If I try to get a connection.State - it's equal to Opened.

So after connection I try to get all data from table "Parts":

string strSQL = "SELECT * FROM Parts";
OleDbCommand command = new OleDbCommand(strSQL, connection);
OleDbDataReader reader = command.ExecuteReader();
reader.Read();

But when I call a command.ExecuteReader I get an error:

ODBC--connection to 'ODBC Driver 17 for SQL Server' failed.

I checked a ODBC Data sources, the "Drivers" tab and I see the same name of driver in the list:

enter image description here

So what this error means? And how can I fix it? Or what should I change to read the data from the table in the .MDB file?

PS: when I try to change a driver and add to the connection string the next line:

Driver={{Microsoft Access Driver (*.mdb, *.accdb)}};

I get an error:

Could not find installable ISAM

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
5ORBEX
  • 81
  • 7
  • Does this answer your question? [How to connect to a MS Access file (mdb) using C#?](https://stackoverflow.com/questions/10374808/how-to-connect-to-a-ms-access-file-mdb-using-c) – June7 Mar 30 '23 at 20:14
  • No, unfortunately. I tried all ways from your link - but all give me some errors. – 5ORBEX Mar 30 '23 at 21:03
  • I am guessing issue is the old MDW workgroup security structure. This shows accessing file via MDW https://stackoverflow.com/questions/12648853/how-can-i-add-an-access-db-to-my-c-sharp-project-when-it-requires-an-mdw-file-to. But since you appear to be doing that already, suggest customer provide you a normal mdb without protection. Why should they care what you do with the data since it won't affect their records? – June7 Mar 30 '23 at 21:13
  • The image that you added says _ODBC Data Source Administrator (64-bit)_. See the following: [Microsoft OLE DB Provider for Jet and Jet ODBC driver are available in 32-bit versions only](https://learn.microsoft.com/en-us/office/troubleshoot/access/jet-odbc-driver-available-32-bit-version) and [ODBC Administrator tool displays both the 32-bit and the 64-bit user DSNs in a 64-bit version of Windows](https://learn.microsoft.com/en-us/troubleshoot/sql/connect/odbc-tool-displays-32-bit-64-bit) – Tu deschizi eu inchid Mar 31 '23 at 17:17
  • There's some code within this [post](https://stackoverflow.com/a/72759270/10024425) that may be useful. – Tu deschizi eu inchid Mar 31 '23 at 17:24

0 Answers0