ODBC connection to ACCDB in web.config - asp.net

Want to connect to ACCDB file as an ODBC (rather than OleDb) data source in ASP.NET but struggling with the connection string. As I plan to deploy the web app from Visual Studio 2019 to Azure, I need something that can make the journey.
Here's what I tried from connectionstrings.com (I discovered not all of those strings are up to date or necessarily convenient for insertion to web.config):
Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\mydatabase.accdb;Uid=Admin;Pwd=;
This returns keyword not supported: driver from IIS Express where I'm doing development.

Hum, that looks ok:
I would suggest this:
Driver={Microsoft Access Driver (*.mdb, *.accdb)};
dbq=C:\test\test44.accdb;driverid=25;fil=MS Access;
maxbuffersize=2048;maxscanrows=8;pagetimeout=5;safetransactions=0;
threads=3;uid=admin;usercommitsync=Yes
the above is what the connection builder in Visual Studio spits out.
and you have Dbq - carefull - caps I believe matters - so try dbq.
Next up:
HUGE HUGE elephant in the room.
are you using a x32 bit driver, or the x64 bit one? YOU MUST match your project bit size (code compile) settings to the driver (YOU MUST!!!).
So this:
you MUST set and force your project to run as x32 bits. (or perhaps install the x64 bit version of Access drivers. AND BE careful. If you are running the x64 bit versions of the drivers, and use Test connection with Visual Studio? It will always fail since VS runs as a x32 bit applcation. you MUST RUN the applcation to test the connection - NOT use test connection with VS connection builders (you might not be using them, but if you are, just trying to save you a day of work wasted).
so, create a x32 config project. And thus this now:
And I assume your sample connection using c: or "root" of the drive is a JUST a example, since most windows now don't allow a file to be used directly from c: root location.

Related

Reading Access .mdb file into R [duplicate]

When trying to make a program on Windows that connects to a database via ODBC, I got the following error:
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.
I'm sure my code is right. It even worked on a different PC.
Why am I getting this error? And How do I fix it?
What causes this error?
The error message tells you, simply put, that the ODBC Driver Manager could not find the driver you specified in your connection string or DSN.
This can have 3 common causes:
The driver you tried to use is not installed on your system
The driver is installed, however, it doesn't match bitness of the code you're running
You made an error in typing the driver name
How do I check which drivers are installed on my system?
You can check the drivers which are installed on your system by going to the ODBC Data Source Administrator. To open it, press ⊞ Win + R, and type in: odbcad32.exe. Then check the tab Drivers for installed drivers. The Name column indicates the exact name you should use in your connection string or DSN.
If you're on 64-bit Windows, that only lists the 64-bit drivers installed on
your system. To see which 32-bit drivers are installed, press press ⊞ Win + R, and type in: C:\Windows\SysWOW64\odbcad32.exe, and go to the Drivers tab again.
The driver is installed, but it might be the wrong bitness, what do I do?
Then, you have two choices, either adjust the bitness your program is running in, or install a driver with a different bitness.
Some of the drivers that are installed by default on Windows only have a 32-bits variant. These can't be used with 64-bits programs.
You can usually identify which bitness a program is running under in task manager. In Windows 10, all 32-bit programs have (32-bit) appended to their name. If that isn't there, you're likely running a 64-bit program, and most modern programming languages and environments run on 64-bit by default, but allow you to switch to 32-bit. However, the specifics for different programming languages are outside the scope of this question.
How can I verify I didn't mistype the driver name?
An ODBC connection string looks like this:
DRIVER={DriverName};ParameterName1=ParameterValue1;ParameterNameN=ParameterValueN;
The driver name part needs to be delimited by curly braces if it might contain special characters, and needs to exactly match the installed driver name, as found in the ODBC Data Source Administrator, including spaces and typographical characters, but excluding capitalization.
Note that for deployed code, the driver must be present on the computer/server running the code.
I don't have the driver, or have the wrong bitness, where do I get the right one?
That depends on which driver you want to use.
A list of common drivers with download locations (all 32-bit and 64-bit at the same URL):
The Microsoft ODBC Driver 17 for SQL Server
The Microsoft Access database driver, which is part of the Microsoft Access Database Engine. Note that simultaneous installations of 32-bit and 64-bit Access ODBC drivers are not supported.
The MySQL ODBC connector by Oracle
The open-source SQLite ODBC driver by Christian Werner (non-official)
psqlODBC, the official PostgreSQL driver
If the driver you want to use isn't listed, the location is usually easily found using Google.
In design mode, a value has been set to the property of
TFDConnection.ConnectionDefName must be empty.

How to connect 64-bit R (without setting it to 32-bit) to 32- bit MS Access [duplicate]

When trying to make a program on Windows that connects to a database via ODBC, I got the following error:
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.
I'm sure my code is right. It even worked on a different PC.
Why am I getting this error? And How do I fix it?
What causes this error?
The error message tells you, simply put, that the ODBC Driver Manager could not find the driver you specified in your connection string or DSN.
This can have 3 common causes:
The driver you tried to use is not installed on your system
The driver is installed, however, it doesn't match bitness of the code you're running
You made an error in typing the driver name
How do I check which drivers are installed on my system?
You can check the drivers which are installed on your system by going to the ODBC Data Source Administrator. To open it, press ⊞ Win + R, and type in: odbcad32.exe. Then check the tab Drivers for installed drivers. The Name column indicates the exact name you should use in your connection string or DSN.
If you're on 64-bit Windows, that only lists the 64-bit drivers installed on
your system. To see which 32-bit drivers are installed, press press ⊞ Win + R, and type in: C:\Windows\SysWOW64\odbcad32.exe, and go to the Drivers tab again.
The driver is installed, but it might be the wrong bitness, what do I do?
Then, you have two choices, either adjust the bitness your program is running in, or install a driver with a different bitness.
Some of the drivers that are installed by default on Windows only have a 32-bits variant. These can't be used with 64-bits programs.
You can usually identify which bitness a program is running under in task manager. In Windows 10, all 32-bit programs have (32-bit) appended to their name. If that isn't there, you're likely running a 64-bit program, and most modern programming languages and environments run on 64-bit by default, but allow you to switch to 32-bit. However, the specifics for different programming languages are outside the scope of this question.
How can I verify I didn't mistype the driver name?
An ODBC connection string looks like this:
DRIVER={DriverName};ParameterName1=ParameterValue1;ParameterNameN=ParameterValueN;
The driver name part needs to be delimited by curly braces if it might contain special characters, and needs to exactly match the installed driver name, as found in the ODBC Data Source Administrator, including spaces and typographical characters, but excluding capitalization.
Note that for deployed code, the driver must be present on the computer/server running the code.
I don't have the driver, or have the wrong bitness, where do I get the right one?
That depends on which driver you want to use.
A list of common drivers with download locations (all 32-bit and 64-bit at the same URL):
The Microsoft ODBC Driver 17 for SQL Server
The Microsoft Access database driver, which is part of the Microsoft Access Database Engine. Note that simultaneous installations of 32-bit and 64-bit Access ODBC drivers are not supported.
The MySQL ODBC connector by Oracle
The open-source SQLite ODBC driver by Christian Werner (non-official)
psqlODBC, the official PostgreSQL driver
If the driver you want to use isn't listed, the location is usually easily found using Google.
In design mode, a value has been set to the property of
TFDConnection.ConnectionDefName must be empty.

Looking for script to add data source node to ODBC

I'm making installation script and I'm using ODBC, how can I automatically add a node to ODBC Data Sources.
Building installer with Visual Studio setup project, but I'm able to run any script for it.
Thank you.
1)
ODBC Data Sources are typically defined in registry entries - located at -
HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI...... (DSNs on 32bit Windows or 64bit Windows)
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI...... (DSNs on 64bit Windows for 32bit Drivers)
That part of the registry contains the "System" DSNs - HKEY_CURRENT_USER contains "User" DSNs.
Of course, all drivers are different so there may be additional stuff required elsewhere too...
2)
You could also consider using File DSNs and ship the fie with the installer.
3)
You could also consider a DSN'less connection - but this would depend on how the ODBC application is coded.

Troubles with JDBC-ODBC, DSN-less connection strings, and 64-bit Windows 7

I'm dealing with an issue that has arisen for an application I've been working on which connects to a Access file via JDBC-ODBC. On other Windows platforms, this issue hasn't been encountered, but on Windows 7 64-bit boxes, attempting to connect with DSN-less connection strings return:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Multiple variations on the string have been attempted, but all of them have returned the same error. Here's how it currently tries to connect:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
StringBuffer databaseConnectionString;
if (SystemUtils.IS_OS_WINDOWS_7) {
databaseConnectionString = new StringBuffer("jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=");
databaseConnectionString.append(databaseFile);
} else {
databaseConnectionString = new StringBuffer("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=");
databaseConnectionString.append(databaseFile);
databaseConnectionString.append(";DriverID=22;READONLY=false}");
}
Examining the driver in the 32-bit ODBC Data Source Admin confirms that the drivers are present. However, when regedt32.exe is used to examine ODBC drivers (HKEY_LOCAL_MACHINE/SOFTWARE/ODBC/ODBCINST.INI/ODBC Drivers), none of them appear.
Can anyone help to shed some light on this?
I found the problem was that I was running the program in 64-bit Java. Although I have yet to successfully have the program detect if it's running in 32-bit or 64-bit Java, I have solved the solution by installing a 32-bit Java runtime environment and using a .bat file that reads as follows:
#echo off
"C:\Program Files (x86)\Java\jre6\bin\java" -D32 -Xmx1024m -jar programName.jar
Thanks for the help!
This was a difficult challenge given the paucity of meaningful error messages from JAVA or MS's ODBC driver. The answers above about down selecting to 32bit Java and MS Access drivers (using AccessDatabaseEngine.exe from MS) did work but cost a significant penalty (about 30%) in processing other actions compared to using 64bit Java. I was unwilling to pay this price so I installed 64bit Java (in conjunction with 32bit, both in a separate directory c:\Java\32 or 64). This latter directory issue was important for me since I was using Apache Geronimo and it would not start if Java was installed in Program Files (x86)... as the (x86) seemed to kill its batch file parsing. I then uninstalled 32bit MS Access and installed 64bit MS Access (AccessDatabaseEngine_x64.exe). Finally, it worked with both higher speed and MDB connection.

JET and ODBC driver missing, can not get data from MDBs

These are MY symptoms: (XP Pro, 32bit)
-Programs that access .mdb databases (aside from Access 2007 itself) can not get any data.
-Using the Data Sources in Visual Studio 2008 to connect to an MDB shows tables, but you can not query. you receive "Unknown Error" from the Microsoft JET Database Engine
-ArcCatalog can not read a personal geodatabase (mdb), after opening the database it has no feature classes within it
-Trying to bring up the properties of a User DSN "MS Access Database" in the ODBC Data Source Administrator returns error
"The setup routines for the Microsoft Access Driver (*.mdb, *.accdb) ODBC driver could not be found. Please reinstall the driver."
I attempted to reinstall latest MDAC (by setting it to compatibility mode of windows 2000) and latest JET driver. Reinstalled XP SP3.
Also tried a lot of regsvr32 gymnastics with the dao350.dll and dao360.dll, uninstalled the dao350, etc, etc. Nothing worked.
(Yes, I'm answering my own question, to record my solution)
I should also note, in addition to above, I couldn't use the SQL Native Client driver either.
In the registry, under HKLM\SOFTWARE\ODBC the \ODBC.INI branch contains any defined connections, and the \ODBCINST.INI contains records for the installed drivers.
I checked a similar development machine, and my ODBCINST.INI was missing A LOT of entries. I blame the ccleaner application that was recently used to clean up my system of junk.
After exporting the registry branch from the other computer, and importing over my existing keys, everything worked again.
Below are some of the core records, to generate a .reg script. You should get the full list from a similar machine to yours.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI]
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\Microsoft Access Driver (*.mdb)]
"UsageCount"=dword:00000002
"Driver"="C:\\WINDOWS\\system32\\odbcjt32.dll"
"Setup"="C:\\WINDOWS\\system32\\odbcjt32.dll"
"APILevel"="1"
"ConnectFunctions"="YYN"
"DriverODBCVer"="02.50"
"FileUsage"="2"
"FileExtns"="*.mdb"
"SQLLevel"="0"
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\Microsoft Access Driver (*.mdb, *.accdb)]
"UsageCount"=dword:00000003
"Driver"="C:\\PROGRA~1\\COMMON~1\\MICROS~1\\OFFICE12\\ACEODBC.DLL"
"Setup"="C:\\PROGRA~1\\COMMON~1\\MICROS~1\\OFFICE12\\ACEODBC.DLL"
"APILevel"="1"
"ConnectFunctions"="YYN"
"DriverODBCVer"="02.50"
"FileUsage"="2"
"FileExtns"="*.mdb,*.accdb"
"SQLLevel"="0"
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\Microsoft Excel Driver (*.xls)]
"UsageCount"=dword:00000002
"Driver"="C:\\WINDOWS\\system32\\odbcjt32.dll"
"Setup"="C:\\WINDOWS\\system32\\odexl32.dll"
"APILevel"="1"
"ConnectFunctions"="YYN"
"DriverODBCVer"="02.50"
"FileUsage"="1"
"FileExtns"="*.xls"
"SQLLevel"="0"
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)]
"UsageCount"=dword:00000003
"Driver"="C:\\PROGRA~1\\COMMON~1\\MICROS~1\\OFFICE12\\ACEODBC.DLL"
"Setup"="C:\\PROGRA~1\\COMMON~1\\MICROS~1\\OFFICE12\\ACEODEXL.DLL"
"APILevel"="1"
"ConnectFunctions"="YYN"
"DriverODBCVer"="02.50"
"FileUsage"="2"
"FileExtns"="*.xls,*.xlsx, *.xlsb"
"SQLLevel"="0"
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\SQL Native Client]
"UsageCount"=dword:00000001
"Driver"="c:\\WINDOWS\\system32\\sqlncli.dll"
"Setup"="c:\\WINDOWS\\system32\\sqlncli.dll"
"APILevel"="2"
"ConnectFunctions"="YYY"
"CPTimeout"="60"
"DriverODBCVer"="09.00"
"FileUsage"="0"
"SQLLevel"="1"
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\SQL Server]
"UsageCount"=dword:00000002
"Driver"="C:\\WINDOWS\\system32\\SQLSRV32.dll"
"Setup"="C:\\WINDOWS\\system32\\sqlsrv32.dll"
"SQLLevel"="1"
"FileUsage"="0"
"DriverODBCVer"="03.50"
"ConnectFunctions"="YYY"
"APILevel"="2"
"CPTimeout"="60"

Resources