Accessing Access db in net standard 2.1

Y a h y a 416 Reputation points
2021-01-09T13:12:59.81+00:00

Hi

First time accessing MS Access in net standard 2.1.

I am using below code to open connection to the MS Access db;

string ConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; Dbq=F:\\My Path\\My DB.MDB;";  
using (OdbcConnection connection = new OdbcConnection(ConnectionString))  
{  
  command.Connection = connection;  
  connection.Open();  
}  

I am getting below error on connection.Open();

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

The machine is a 64 bit Win 10 with 32 bit MS Office.

The driver entries in both 32 bit and 64 bit ODBC are shown below.

What am I doing wrong?

Thanks

Regards

54939-hs-odbc.png

Developer technologies .NET Other
0 comments No comments
{count} votes

Accepted answer
  1. Y a h y a 416 Reputation points
    2021-01-10T05:57:15.847+00:00

    Hi

    I solved this by making sure my projects are all targeting x86.

    Regards

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Abdulhakim M. Elrhumi 356 Reputation points
    2021-01-09T13:43:45.753+00:00

    Hi
    Standard security
    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb;Persist Security Info=False;
    Access 2007Access 2010Access 2013
    With database password
    This is the connection string to use when you have an Access 2007 - 2013 database protected with a password using the "Set Database Password" function in Access.
    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb;Jet OLEDB:Database Password=MyDbPassword;
    Some reports of problems with password longer than 14 characters. Also that some characters might cause trouble. If you are having problems, try change password to a short one with normal characters.
    Note! Reports say that a database encrypted using Access 2010 - 2013 default encryption scheme does not work with this connection string. In Access; try options and choose 2007 encryption method instead. That should make it work. We do not know of any other solution. Please get in touch if other solutions is available!
    Access 2007Access 2010Access 2013
    DataDirectory functionality
    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\myAccessFile.accdb;Persist Security Info=False;
    Access 2007Access 2010Access 2013
    Network Location
    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\server\share\folder\myAccessFile.accdb;
    Microsoft Access accdb ODBC Driver
    Standard Security
    Driver={Microsoft Access Driver (*.mdb, .accdb)};Dbq=C:\mydatabase.accdb;Uid=Admin;Pwd=;
    Access 2007
    Access 2010
    Access 2013
    Workgroup
    Driver={Microsoft Access Driver (
    .mdb, *.accdb)};Dbq=C:\mydatabase.accdb;SystemDB=C:\mydatabase.mdw;
    No changes were made to the .mdw file format for Office Access 2007. The Office Access 2007 Workgroup Manager creates .mdw files that are identical to those that are created in Access 2000 through Access 2003. The .mdw files that are created in those earlier versions can be used by databases in Office Access 2007.

    Access 2007
    Access 2010
    Access 2013
    Exclusive
    Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\mydatabase.accdb;Exclusive=1;Uid=admin;Pwd=;
    Access 2007
    Access 2010
    Access 2013
    Enable admin statements
    To enable certain programatically admin functions such as CREATE USER, CREATE GROUP, ADD USER, GRANT, REVOKE and DEFAULTS (when making CREATE TABLE statements) use this connection string.

    Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\mydatabase.accdb;Uid=Admin;Pwd=;ExtendedAnsiSQL=1;

    Best Regards.

    Please click the Mark as answer button and vote as helpful if this reply solves your problem.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.