3
votes

I was trying to built a asp.net web app with the connection string defined in the webconfig file. When I try to debug I am getting the following exception:

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

The connection string looks like this:

connectionString="Driver={MySQL ODBC 5.1 Driver};server=XX.XX.XX.XX;port=3306;database=db_name;user=username;pwd=pass;option=3;" providerName="System.Data.Odbc"/>

The driver is installed and I can see it listed in the 'ODBC Data Source Administrator'.

I tried changing the build configuration to 'Any CPU', still it failed.

Can somebody help me out to figure whats going on here??

Thanks,

Uday

2
Can you write a test that yields the same exception without going through your web app?Austin Salonen
The name of the driver in the ODBC Data Administrator is exactly : "MySQL ODBC 5.1 Driver" ?aleroot
I noticed there's 32-bit and 64-bit versions of the MySQL ODBC driver. Maybe the console app is using the one you have installed, and the web-app is looking for the other architecture? Also, why use the ODBC driver instead of the native .NET connector?millimoose
Its working now!! I installed the 32bit MySQL driver and it worked. I guess no matter what my build configuration is, my app is looking for 32bit driver. But how come my console app work and not the web app?usp
@Uday The .NET code is in and of itself not architecture-specific. So whether a .exe runs in 32-bit or 64-bit mode is a matter of which .NET runtime you use to "interpret" it. My guess is that the development server that runs ASP.NET apps from Visual Studio always runs in 32-bit mode regardless of how your VS project is set up.millimoose

2 Answers

6
votes

If you have installed the x64 version of the ODBC driver you can use it compiling the executable as default (both CPU) otherwise you have to compile the executable as x86 only and use the x86-32 driver.

Keep in mind that by default on x64 os an application compiled as both CPU (x64 and x86) will use the 64bit version of the driver, this means that if you install the 32bit version of the ODBC driver and compile the executable as Both CPU or x64 you will get the error, so you have to compile the application only x86.

0
votes

You could configure VS to use IIS instead of the internal one, plus you would get more experience configuring IIS correctly for your web app (i.e. Windows Server 2k8 R2 has pretty drastic configuration/security differences than previous versions). If you configure your AppPool to run under 64 bit then your code should also run in 64 bit mode.