Mysql version was something 5.6.35-81.0-log
.NET framework 4.0
Visual Studio Community 2017
Shared Web Hosting Trust Level = Medium
Follow the steps to you finally publish successfully your application:
- Install the mysql-connector-net-6.3.9 (download)
- Install the mysql-for-visualstudio-1.2.8 (download)
- Reference the 4 mysql dlls in your project
- mysql.data.dll (download)
- mysql.data.entity.dll (download)
- mysql.visualstudio.dll (download)
- mysql.web.dll (download)
- Go to your project Properties > AssemblyInfo.cs and add the 2 assemblies:
- [assembly: SecurityRules(SecurityRuleSet.Level1)]
- [assembly: System.Security.AllowPartiallyTrustedCallers]
- Make sure your webconfig file has the following lines:
- <clear />
- <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient"
- description=".Net Framework Data Provider for MySQL"
- type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,
- Version=220.127.116.11, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
Now, that you already solved your problem and you are still here I would like to let off somethings.
First of all, I am so relieved that I finally solved this problem. Imagine, you finish your project using Entity Framework, everything is working and when you are publishing your project you realise that nothing works. What a feeling, huh?
This image represents the number of mysql connectors that I installed to finaly make the Entity works in my web host with medium level.
I had a Brazilian web host called Locaweb where the trust level is set as Medium. The real problem is that it was Full trust level before, and then they changed due to security permissions. Guess what? We developers will swallow one's pride.
Anyway, spending 7-8 hours in a row trying to figure out how can we use the Entity framework in these shared web hosts I learned important things such as:
- Careful to install some updated connectors/extensions such as Devert. It might be really simple to implement it, but the real problem will happen when you publish in a shared webhost (if you actually have one of course).
- MySQL has an amazing website where you can download all the previous application versions just by clicking on the Archives tab
- Your webconfig does not include every config of your application. You might check the machine config in the Windows -> MicrosoftNET -> Framework -> v4 -> Configs folder
- MySQL website provides you with the source code of each MySQL connector, I found it so amazing =D
I would like to thank Lúcio Rogério for this amazing post it really helped me. However it is important mentioning that I still needed to add the 2 assemblies in the project.
There was another post from rbrundritt which was pretty cool as well, however when I installed the MySQL connector 18.104.22.168, I was not able to edit the source project because it was requiring Visual Studio 2005 and I really did not want to install it.
Finally, I will put down here some errors I got it during this bug fix to help some people with the same problem in the future. Cya guys!
[ArgumentException: Unable to find the requested .Net Framework Data Provider.
It may not be installed.]
System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1402071
System.Data.EntityClient.EntityConnection.GetFactory(String providerString) +35
[SecurityException: Request for the permission of type ‘System.Security.Permissions.SecurityPermission, mscorlib, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.] MySql.Data.MySqlClient.MySqlTrace..cctor() +0
System.Security.SecurityException: That assembly does not allow partially trusted callers.
Wow, and I forgot to give you the link of the webpage where I used Entity Framework. So here you are. [SOLVED MySQL connector with ENTITY FRAMEWORK WORKING in Medium Trust hosting environments]