添加 mysql dll 引用
WebConfig 配置:
1.先添加connectionstrings,providerName 换成 mysql的
<connectionStrings> <add name="ECSWebDb" connectionString="User Id=xxx;server=.;Database=xxx;pwd=xxx;Persist Security Info=True;" providerName="MySql.Data.MySqlClient"/> </connectionStrings>
2.EF 添加Provider的 配置
<entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="mysqllocaldb" /> </parameters> </defaultConnectionFactory> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/> </providers> </entityFramework>
3. system.data 增加 DbProviderFactories
<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.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> </DbProviderFactories> </system.data>