我的Sql错误,给定的键不存在于字典中

问题描述 投票:0回答:1

我在连接到数据库服务器时遇到以下异常。

Exception: An error occurred while executing the command definition. See the inner exception for details.
StackTrace:    at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
   at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Lorax.DataModel.GenericRepository.GenericRepository`1.GetAll()
   at LoraxQueueConsumer.LoraxScheduler.CheckDB_Conn() in D:\Lorax\AthenaQueueConsumer\LoraxScheduler.cs:line 154
Inner Exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at MySql.Data.MySqlClient.CharSetMap.GetCharacterSet(DBVersion version, String CharSetName)
   at MySql.Data.MySqlClient.MySqlField.SetFieldEncoding()
   at MySql.Data.MySqlClient.NativeDriver.GetColumnData(MySqlField field)
   at MySql.Data.MySqlClient.NativeDriver.GetColumnsData(MySqlField[] columns)
   at MySql.Data.MySqlClient.Driver.GetColumns(Int32 count)
   at MySql.Data.MySqlClient.ResultSet.LoadColumns(Int32 numCols)
   at MySql.Data.MySqlClient.ResultSet..ctor(Driver d, Int32 statementId, Int32 numCols)
   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlDataReader.Close()
   at MySql.Data.MySqlClient.MySqlCommand.ResetReader()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
Source: System.Data.Entity

以下是使用的配置:
数据库版本:8.0.35
实体框架版本:5.0.0
点网连接器版本:6.8.3

使用数据库版本8.0.28,我没有收到上述异常。一切都工作正常。

我尝试在连接字符串中添加 charset=utf8mb3; 但仍然遇到异常。

请在此提供帮助。

c# mysql entity-framework entity-framework-5 mysql-connector
1个回答
0
投票

这是旧版本 MySql.Data 中的一个已知错误,在将服务器升级到 MySQL Server 8.0.29 或更高版本后会发生:https://bugs.mysql.com/bug.php?id=107259

您需要更新到MySql.Data v8.0.30或更高版本。

© www.soinside.com 2019 - 2024. All rights reserved.