What is ConnectionString to create OdbcConnection for mdb access file

I want to connect from C # to an MDB access file using Odbc.

When I try to execute

OdbcConnection con = new OdbcConnection(
    "Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\\temp\\test.mdb;");

      

I am getting the following exception:

exc {System.Data.Odbc.OdbcException (0x80131937): ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
   at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
   at System.Data.Odbc.OdbcConnectionHandle..ctor(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle)
   at System.Data.Odbc.OdbcConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.Odbc.OdbcConnection.Open()
   :

      

What's the problem here? He complains that "No datasource name was found and no default drivers specified", but did I specify a driver?

I got the connection string using here http://www.connectionstrings.com/access#net-framework-data-provider-for-odbc

+3


source to share


3 answers


Oh, I just found the source of my problem. I think others might run into this:

I am writing a .net application that runs on a 32 bit .net vm when the OS is 32 bit Windows and in a 64 bit virtual environment when the OS is 64 bit Windows. Using 2 odbcad32.exe in syswow and system32 (yes, both are named odbcad32.exe, although the one in system32 for 64-bit, and yes that's correct too) I found out that I only have the Access MdB driver for odbc32 bits. So when my application is running on 64bit Windows, .net wants to use the 64bit version of odbc and cannot find the Driver.



Ok, now I need a 64-bit access driver which doesn't exist according to this enter the link here here . Okay, the post is old, so maybe it exists now?

When I force Plattform in my project settings on x86 it works. Of course, this also makes my application run in a 32-bit .net vm.

+3


source


Use web config setup like example below



<add      name="ODBCDataConnectionString"   connectionString="Driver=ODBCDriver;server=ODBCServer;"   providerName="System.Data.Odbc"   />

      

0


source


You can create a udl file, create a connection, and then open the file in notepad to see the connection string. This has helped me in the past -

http://msdn.microsoft.com/en-us/library/e38h511e%28v=vs.71%29.aspx

Using this you can create a regular connection like in the odbc tool and make sure it works.

Hope it helps.

0


source







All Articles