MySql数据实体EF6中等信任

时间:2017-01-18 03:40:59

标签: c# mysql entity-framework web-config

我们目前通过Hostgator在共享的Windows服务器上。他们正在强制共享服务器在Medium Trust中运行。他们在GAC中有MySql.Data.DLL(6.9.7)。问题是它们在GAC中没有MySql.Data.Entity.EF6.DLL,也不会为我安装它。所以我尝试从gac引用MySql.Data dll,然后从我们的项目中引用MySql.Data.Entity.EF6.dll(6.9.9)。当我这样做时,我收到一个安全错误。我假设这是由于EF6 DLL需要完全信任。对此有何解决方案?感谢

错误:

  

{“消息”:“发生了错误。”,“ExceptionMessage”:“请求   类型的许可   'System.Security.Permissions.EnvironmentPermission,mscorlib,   Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'   失败 “” ExceptionType。 “:” System.Security.SecurityException “ ”堆栈跟踪“:”   在System.Security.CodeAccessSecurityEngine.Check(对象需求,   StackCrawlMark&安培; stackMark,Boolean isPermSet)\ r \ n at   System.Security.CodeAccessSecurityEngine.Check(的CodeAccessPermission   cap,StackCrawlMark& stackMark)\ r \ n at   System.Security.CodeAccessPermission.Demand()\ r \ n at   System.Environment.GetEnvironmentVariable(String variable)\ r \ n at   MySql.Data.MySqlClient.MySqlConnectAttrs.Is64BitOS()\ r \ n at   MySql.Data.MySqlClient.MySqlConnectAttrs.get_Platform()“}

WebConfig:

<configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>

<entityFramework>
<providers>
    <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
    <remove invariant="MySql.Data.MySqlClient" />
    <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>

<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" />
<bindingRedirect oldVersion="0.0.0.0-6.9.9.0" newVersion="6.9.7.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="MySql.Data.Entity.EF6" publicKeyToken="c5687fc88969c44d" />
<bindingRedirect oldVersion="0.0.0.0-6.9.9.0" newVersion="6.9.9.0" />
</dependentAssembly>

enter image description here

1 个答案:

答案 0 :(得分:0)

我不知道你提到的错误。但我建议你仔细阅读本页https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html
您的WebConfig不是格式

&#13;
&#13;
<connectionStrings>
    <add name="MyContext" providerName="MySql.Data.MySqlClient"
        connectionString="server=localhost;port=3306;database=mycontext;uid=root;password=********"/>
</connectionStrings>
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
    <providers>
        <provider invariantName="MySql.Data.MySqlClient"
            type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/>
        <provider invariantName="System.Data.SqlClient"
            type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
    </providers>
</entityFramework>
&#13;
&#13;
&#13;