To those out there having an issue with the MySQL .NET Connector on ASP.NET 2.0, here's a way to make the MySql.Data.dll work on shared hosting.
Problem: After debugging your site on your machine with Visual Studio 2005, everything seems to work fine, but after publishing it to your host server, you get a server error with this:
System.Security.SecurityException: That assembly does not allow partially trusted callers.
Solution: Recompile the library with a few changes to the AssemblyInfo.cs file.
The solution file is typically located in C:\Program Files\MySQL\MySQL Connector Net 1.0.9\Source\MySqlClient, and the modified MySql.Data.dll file will be located in C:\Program Files\MySQL\MySQL Connector Net 1.0.9\Source\MySqlClient\bin\net-2.0\Release. These paths may vary depending on your chosen installation settings and version.
Open the solution in Visual Studio and open AssemblyInfo.cs, and add the following code:
using System.Security; [assembly: AllowPartiallyTrustedCallers()]
Compile, and use the modified library located in the folder mentioned above. This fix should allow you to use the library without any problems.
If you liked this tutorial. Please, consider sharing it. Thank you!
Tags: .NET, ASP.NET, C#, MySQL, Programming
Want to leave a comment?