无法使用Visual Studio从MySql数据库+创建ADO.NET实体数据模型
我正在尝试添加从MySql数据库(8.0.21.0)生成的ADO.NET实体数据模型,我已经按预期安装了所有组件(MySql Connector,用于Visual Studio的MySql),选择了要包含的表后,我收到了以下异常.
I am trying to add ADO.NET Entity Data Model generated from MySql Database(8.0.21.0), I have installed everything as expected (MySql Connector, MySql for Visual Studio) and after selecting the tables I want to include I receive the below exception.
MySql 8.0.21.0,Visual Studio 2019,实体框架6.4.4,控制台应用程序
MySql 8.0.21.0, Visual Studio 2019, Entity framework 6.4.4, Console Application
Unable to generate the model because of the following exception: 'System.Data.Entity.Core.EntityCommandExecutionException:
An error occurred while executing the command definition.
See the inner exception for details.
---> MySql.Data.MySqlClient.MySqlException: Fatal error encountered during command execution.
---> MySql.Data.MySqlClient.MySqlException: Fatal error encountered attempting to read the resultset.
---> MySql.Data.MySqlClient.MySqlException: Reading from the stream has failed.
---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Security._SslStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
--- End of inner exception stack trace ---
at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
--- End of inner exception stack trace ---
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
--- End of inner exception stack trace ---
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.EntityFramework.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext`1 c)
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
--- End of inner exception stack trace ---
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.Execute(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Entity.Core.EntityClient.EntityCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.FunctionDetailsReader..ctor(EntityCommand command, Version storeSchemaModelVersion)
at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.EntityStoreSchemaGeneratorDatabaseSchemaLoader.LoadFunctionDetails(IEnumerable`1 filters)
at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.EntityStoreSchemaGeneratorDatabaseSchemaLoader.LoadStoreSchemaDetails(IList`1 filters)
at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.GetStoreSchemaDetails(StoreSchemaConnectionFactory connectionFactory)
at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.CreateStoreModel()
at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.GenerateModel(List`1 errors)
at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModels(String storeModelNamespace, ModelBuilderSettings settings, List`1 errors)
at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModel(ModelBuilderSettings settings, IVsUtils vsUtils, ModelBuilderEngineHostContext hostContext)'.
Loading metadata from the database took 00:00:00.4895530.
Generating the model took 00:00:09.6119343.
我已经为同一问题苦苦挣扎了2天.我使用的是MySQL 8.0.18(服务器,NET连接器等),适用于Visual Studio v1.2.9的MySql,nuget包:MySql.Data + MySql.Data.EntityFramework,一个月前一切正常.上周,我将nuget软件包更新为v8.0.21,并且数据库连接受到干扰,因此我将MySql更新为v8.0.21版本.我对数据库进行了更改,当我使用ADO.NET实体数据模型向导时,遇到了同样的异常.尝试了所有内容,但没有成功,因此我做了以下操作以返回到以前的工作状态:
I've been struggling with the same problem for 2 days. I was using MySQL 8.0.18 (Server, NET Connector etc.), MySql for Visual Studio v1.2.9, nuget packages: MySql.Data + MySql.Data.EntityFramework and everything was working just fine a month a ago. Last week i updated the nuget packages to v8.0.21 and the db connection got disturbed so i updated my MySql to version v8.0.21. I made changes to the database and when i used the ADO.NET Entity Data Model wizard, i got the same exception. Tried everything but it did not work so i did the following to go back to the past working state:
注意:如果您打算关注,我建议您按照此顺序关注:
Note: If you plan to follow, I advise you to follow in this order:
- 首先安装MySql for Visual Studio v1.2.9
- 创建所有当前的MySql数据库备份.借助本指南完全卸载MySql .然后重新启动系统.
- 下载并安装MySql v8.0.18(包括NET连接器的所有组件)
- 将所有数据库还原到此已安装的版本中.
- 在您的项目中,您可能还必须降级软件包.我将EntityFramework降级到v6.2.0,将MySql.Data和MySql.Data.EntityFramework降级到v8.0.18
- 现在创建一个新的ADO.NET实体数据模型,此时一切正常.
我使用最新版本的MySql v8.0.21和软件包尝试了所有操作,但无法正常工作.一个可能的原因可能是您的应用程序的MySql NET连接器和目标.NET框架版本可能彼此不兼容.在MySql NET连接器版本和Visual Studio版本之间,情况也可能相同.这可能不是解决问题的实际方法,但这是使它起作用的一种方法.
I tried everything using the latest versions of MySql v8.0.21 and packages but couldn't get things to work. One possible reason could be that the MySql NET Connector and the target .NET framework version of your application may be incompatible with each other. It may also be the same case between MySql NET Connector version and Visual Studio version. This may not be the actual solution to your problem but it's one way of getting it to work.