Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

exception

odbc

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

like image 661
Isaac Hili Avatar asked Jun 11 '26 12:06

Isaac Hili


1 Answers

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;");
like image 82
Isaac Hili Avatar answered Jun 16 '26 04:06

Isaac Hili



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!