3
votes

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: enter image description here

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

2

2 Answers

2
votes

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;");
0
votes

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.