C# ODBC Connection String for Access & Excel

Before we can build the connection string we need to ensure that the ODBC
drivers are available on our system.

ODBC Drivers

The standard ODBC drivers for MS Access 97 (*.mdb) and MS Excel 97 (*.xls)
should be available on all Windows installations:

Microsoft Access Driver (*.mdb)Microsoft Excel Driver
(*.xls)

... but the MS Office 2010 ODBC drivers for *.xlsx and *.accdb might
not be installed on your system.This means it might be required
to install the drivers first, if you want to use an Excel file with the extension
.xlsx or an Access file with the extension .accdb.

Install ODBC Driver for *.accdb and *.xlsx

Important: There are different drivers for 32bit and 64bit
applications. If you want to build a 32bit application, then you need to install
the 32bit version of the driver, because a 32bit application cannot use the
64bit driver and a 64bit application cannot use the 32bit driver!

ODBC Connection String

The connection string for MS Access and MS Excel has the following syntax:

The "driver" can be different depending on the language, so it could be required
to enumerate the installed drivers and search for the file extension.e.g.
"Microsoft Excel Driver" is called "Microsoft Excel Treiber" in German.

Enumerate ODBC Drivers

The system stores a list of the installed ODBC drivers in the registry HKEY_LOCAL_MACHINE.
There are two different locations for 32bit and 64bit drivers:

If you prefer e.g. the English driver: check if the English driver is installed
- otherwise use any valid driver for the file extension.

Disclaimer: The information on this page is provided "as is" without warranty of any kind.
Further, Arclab Software does not warrant, guarantee, or make any representations
regarding the use, or the results of use, in terms of correctness, accuracy, reliability, currentness, or otherwise.
See: License Agreement