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:
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