当前位置:网站首页>Connection between mysql+c ef6

Connection between mysql+c ef6

2022-06-09 15:16:00 Game programming

It took three days , Stepped on countless pits , At last, half the success was achieved
Can now pass Code First Model generation database , however Model First The model will still flash back

Mysql+C# EF6 The connection between - The first 1 Zhang
Mysql+C# EF6 The connection between - The first 2 Zhang
Mysql+C# EF6 The connection between - The first 3 Zhang
Mysql+C# EF6 The connection between - The first 4 Zhang
<?xml version="1.0" encoding="utf-8"?><configuration>  <configSections>    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->  </configSections>  <startup>    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />  </startup>  <runtime>    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">      <dependentAssembly>        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />      </dependentAssembly>      <dependentAssembly>        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />        <bindingRedirect oldVersion="0.0.0.0-6.8.8.0" newVersion="6.8.8.0" />      </dependentAssembly>    </assemblyBinding>  </runtime>  <entityFramework>    <providers>      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />    </providers>    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">      <parameters>        <parameter value="mssqllocaldb" />      </parameters>    </defaultConnectionFactory>  </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.8.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />    </DbProviderFactories>  </system.data>  <connectionStrings>    <add name="connStr" connectionString="data source=127.0.0.1;user=root;password=root;database=sqltest;" providerName="MySql.Data.MySqlClient" />    <add name="Model1" connectionString="server=127.0.0.1;port=3306;user=root;password=root; database=Model1;sslmode=none;" providerName="MySql.Data.MySqlClient" />  </connectionStrings></configuration>

( Make complaints about it ,sql server It's my son , All the way down smoothly , what bug either , You don't need the next pile of plug-ins )
The following describes the pitfalls and solutions encountered :
(1) The first pit , To install plug-ins , And the version of the plug-in must correspond to , Otherwise, the database cannot be connected , The version I installed is as follows

Mysql+C# EF6 The connection between - The first 5 Zhang

(2) The second pit , Version match , Version mismatch will display “System.ArgumentException: Option not supported…”
The reason is the version problem , Refer to two articles to solve :
https://zhuanlan.zhihu.com/p/43190042
https://www.cnblogs.com/tthjHiroki/p/8269480.html
Roughly speaking :Oracle In the upgrade MySql.Data To 8.x After version , There is no direct use of the original MySql.Data.Entity Also upgrade to 8.x, But changed its name to MySql.Data.EntityFramework, however Nuget The configuration information in is not correct , So there will be bug, The solution is to reduce the version
My version , For reference only :
①Install-Package EntityFramework -Version 6.1.3
②Install - Package MySql.Data - Version 6.8.8
③Install - Package MySql.Data.Entity - Version 6.8.3
(3) Modify the default : Configure connection string ( Default sqlserver, It has to be changed to mysql Of )

Mysql+C# EF6 The connection between - The first 6 Zhang

(4)context Model prefix

           DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]

If you don't do this, you won't generate a model , It's also a pit , because sql server No such problem
(5)mysql: call SSPI Failure , See inner exception .
Solution :
Connection string add :

sslmode=none;

(6) Tips “Authentication plugin ‘caching_sha2_password‘ cannot be loaded…”
Only need to my.ini In the document default_authentication_plugin Property set to mysql_native_password that will do
That is to say default_authentication_plugin = mysql_native_password
(7) Can't find my.ini file
I unpacked the installation , At this point, find the installation directory , Build your own my.ini service , And then restart mysql service
Reference resources :https://blog.csdn.net/qq_43045747/article/details/125043557
It is not easy to , Every step is a pit , It's still honest and practical sql server Well
author : The sword gives birth and the sword gives death

Game programming , A game development favorite ~

If the picture is not displayed for a long time , Please use Chrome Kernel browser .

原网站

版权声明
本文为[Game programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091446414353.html