first of all, I would like to say that I have tried to resolve this issue for several hours through trying a bunch of different approaches from people that had the same issues, but to no avail. I am pretty clueless at this point.
I am using MySql.Data and MySql.Data.Entity dlls (version 6.7.4) which I have referenced in my ASP.NET 4.5 application.
I have managed to connect (locally) to my database and query it without a problem.
SqlConnection = new MySqlConnection("server=localhost;User Id=;Password=;database=;");
The problem is within a medium trust shared environment. I get the following error (when attempting to connect to the database):
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
I have also tried to add "Integrated Security=True;includesecurityasserts=true;autoenlist=false;" to the connection string, but didn't help.
I have also tried to add this in my web.config:
<mscorlib>
<security>
<policy>
<PolicyLevel version="1">
<SecurityClasses>
<SecurityClass Name="MySqlClientPermission" Description="MySql.Data.MySqlClient.MySqlClientPermission, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
</SecurityClasses>
<NamedPermissionSets>
<PermissionSet class="NamedPermissionSet" version="1" Name="ASP.Net">
<IPermission class="MySqlClientPermission" version="1" Unrestricted="true">
</IPermission>
</PermissionSet>
</NamedPermissionSets>
</PolicyLevel>
</policy>
</security>
But that did not work either.
I have then tried to add a bunch of PermissionSets, IPermissions and what not in the web.config by following some articles, but that didn't seem to work for me.
Please note:
Any and all help is appreciated! Thank you!
EDIT
I have changed the way I communicate with the database with an ODBC connection. Works properly using full trust, but as soon as I change to medium trust, I get basically the same error as with MySql connectors.
Request for the permission of type 'System.Data.Odbc.OdbcPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Can anyone please point me to the right direction, such as a full example on how you managed to make it work, because I can't seem to make this work using medium trust...
Thanks!
I ended up using an ODBC connection.
Driver={MySQL ODBC 5.1 Driver};Server=myServerAddress;Database=myDataBase; User=myUsername;Password=myPassword;Option=3;
http://www.connectionstrings.com/mysql-connector-odbc-5-1/remote-database/
I know you tried the following solution:
you can not deploy this on medium trust. It required full trust for proper working. May be you are using the medium trust server for deployment. You need full trust for the deployment. Only solution is you need to run it on Full trust environment. You need to contact with your server support and change the trust level medium to Full.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With