Problem with ASP.NET using MySQL Connecting through ODBC Driver in some Hosting Servers
Recently I hosted one of my asp.net 4.0 application which is using MySQL as backend and I decided to use MySQL .NET connector to access the MySQL server. I hosted one of the local server and its works fine but i got some consistency issues with my local server and decided to shift my application to GoDaddy which they ensure our application will be 24 X 7 inactive.
I moved the application successfully but when I try to run the application through the browser I cannot able to connect to the database when I dig into the issue through my logs I came to know that GoDaddy doesn’t support MySQL .NET connector DLL because GoDaddy will run only components and application which are Fully Trusted. When I read the blogs regarding this DLL I came to know Oracle has built this component as partial trusted (medium trust) which means I cannot use anymore with my application to host in GoDaddy. But here I have 2 options
- Need to place my MySql .Net connector component to the GAC of GoDaddy server.
- Need to remove using MySql .Net connector component in my application.
In the above options, option-1 GoDaddy doesn’t allow me to do so. Now I have only option-2, I removed code related to MySql .Net connector component and removed the reference to it and I try to connect mySQL database through ODBC (Object Database Connector). Which I successfully implemented in my application and working fine on my local computer and I updated the same over the hosting server (in my case GoDaddy), Interestingly still i am unable to connect to the Database, Now when I log my application to find the root cause of the issue, following are the error it’s throwing:
Request for the permission of type ‘System.Data.Odbc.OdbcPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.
OOPS, I realized that GoDaddy also needs my application to be fully trusted which I need to configure in my application via. web.config in System.web section as shown below:
<trust level="Full"/>
Once I changed this and made my application fully trusted with this simple configuration change, My Application working like a charm.
The reason behind on writing this post is, I worked nearly 5 hrs to fix this issue and I cannot find any direct help from any blogs so I decided to keep this information on my blog to make others time save.
Thank You,
Happy Coding…..