简体   繁体   中英

C# - Data source name not found and no default driver specified Exception Error

Good morning,

I am currently trying to use an ODBC connection to connect to my database.

private OdbcConnection connect = new OdbcConnection("DSN = My Data Source; DATABASE = MyDB;"); 
// From research I discovered that some people use DB instead of DATABASE.

After Googling the error, I found out that as the name specifies this occurs when there is no such name in the ODBC DSN connections. The problem could also arise when the application is looking for the 32-bit version, however, only the 64-bit version is setup. I went to System32 and SysWOW64 , and made sure to setup a System DSN ODBC connection for each ODBCAD32 executable.

The error: 在此处输入图片说明

Any suggestions? Could it be that this is happening due to the fact that my DSN has spaces involved in the name? The DSN is properly setup due to the fact that it is being used by other software.

Thanks, Isaac

OK so even though I set the user within the ODBC connection, I had to set the User ID and Password as such:

private OdbcConnection connect = new OdbcConnection("DSN=My Data Source;  UID=User;  PWD=Password;");

Also another issue was that I usually apply spaces surrounding the equal sign. This resulted in a connection error. Therefore do NOT do as below:

private OdbcConnection connect = new OdbcConnection("DSN = My Data Source;  UID = User;  PWD = Password;");

This error usually occur because of Insufficient Permissions to Read the DSN Registry Key

Grant the user account Read access to the specified ODBC System DSN registry key as follows: Determine which account is used to process the request for the ASP page. From the Start menu, click Run , type regedt32.exe , and then click OK to start Registry Editor. In the HKEY_LOCAL_MACHINE window, browse to the HKLM\\SOFTWARE\\ODBC\\ODBC.INI key. The ODBC.INI key contains a subkey for each ODBC SYSTEM DSN that is registered on the server. Click the DSN registry key for the DSN that is specified in the ADO connection string. From the Security menu, click Permissions . Add the user account that you identified in step 1 to the list of users who can access this key, and select the Read check box for this user. Click Apply , and then close Registry Editor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM