Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
539 views
in Technique[技术] by (71.8m points)

database - Why am I getting "Data source name not found and no default driver specified" and how do I fix it?

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?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  1. The driver you tried to use is not installed on your system
  2. The driver is installed, however, it doesn't match bitness of the code you're running
  3. 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:WindowsSysWOW64odbcad32.exe, and go to the Drivers tab again.

enter image description here

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):

If the driver you want to use isn't listed, the location is usually easily found using Google.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...