When trying to write a program on Windows that connects to a database via ODBC, the following error occurs:
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.
I'm sure my code is correct. It can even run on another computer.
Why am I getting this error? How can I fix it?
P粉1470452742023-10-19 13:15:54
In design mode, the value has been set to the property
TFDConnection.ConnectionDefName
Must be empty.
P粉2210464252023-10-19 12:51:59
Simply put, the error message tells you that the ODBC Driver Manager cannot find the driver you specified in the connection string or DSN.
There may be 3 common reasons for this:
You can check the drivers installed on your system by going to the ODBC Data Source Administrator. To open it, press ⊞ Win R and enter: odbcad32.exe
. Then check tab Drivers for installed drivers. The Name column indicates the exact name you should use in the connection string or DSN.
If you are using 64-bit Windows, only the files installed on
your system. To see which 32-bit drivers are installed, press ⊞ Win R, then enter: C:\Windows\SysWOW64\odbcad32.exe code>, then again Go to the "Drivers" tab.
Then you have two options, either adjust the number of bits the program runs at, or install a driver with a different number of bits.
Some drivers installed by default on Windows only have 32-bit variants. These cannot be used with 64-bit programs.
You can usually identify the number of bits a program is running in Task Manager. In Windows 10, all 32-bit programs have (32-bit) appended to their names. If it's not there, you're probably 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 specific details of different programming languages are beyond the scope of this question.
The ODBC connection string looks like this:
DRIVER={DriverName};ParameterName1=ParameterValue1;ParameterNameN=ParameterValueN;
If the driver name part may contain special characters, it needs to be separated by braces and needs to match the installed driver name exactly (as shown in the ODBC Data Source Administrator), including spaces and typographical characters, but Exclude capital letters.
Please note that for deployed code, the driver must exist on the computer/server running the code.
It depends on which driver you want to use.
List of common drivers and download locations (all 32-bit and 64-bit at the same URL):
If the driver you want to use is not listed, you can usually easily find the location using Google.