Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更新条目时出错。有关详细信息,请参阅内部异常。-Linq到实体_C#_Database_Xna_Linq To Entities - Fatal编程技术网

C# 更新条目时出错。有关详细信息,请参阅内部异常。-Linq到实体

C# 更新条目时出错。有关详细信息,请参阅内部异常。-Linq到实体,c#,database,xna,linq-to-entities,C#,Database,Xna,Linq To Entities,我一直在四处张望,但我似乎不知道出了什么问题 目前,我正试图更新我的数据库与新的高分时,球员死亡。但无论我选择如何尝试和保存,它总是向我抛出异常 代码: 我一次又一次地检查,但我似乎不知道问题出在哪里 任何帮助都将受到感谢 例外情况: System.Data.UpdateException was unhandled Message=An error occurred while updating the entries. See the inner exception for detail

我一直在四处张望,但我似乎不知道出了什么问题

目前,我正试图更新我的数据库与新的高分时,球员死亡。但无论我选择如何尝试和保存,它总是向我抛出异常

代码:

我一次又一次地检查,但我似乎不知道问题出在哪里

任何帮助都将受到感谢

例外情况:

System.Data.UpdateException was unhandled
  Message=An error occurred while updating the entries. See the inner exception for details.
  Source=System.Data.Entity
  StackTrace:
       at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
       at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
       at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
       at System.Data.Objects.ObjectContext.SaveChanges()
       at MatematikSpilMenu.SaveBunniesSceen.SaveHighscore() in MatematikSpilMenu\SaveBunniesSceen.cs:line 173
       at MatematikSpilMenu.SaveBunniesSceen.Update(GameTime gameTime, Boolean otherScreenIsActive, Boolean coveredByOtherScreens) in C:\Users\Etarnalazure-Alien\documents\visual studio 2010\Projects\MatematikSpilMenu\MatematikSpilMenu\MatematikSpilMenu\SaveBunniesSceen.cs:line 110
       at MatematikSpilMenu.ScreenManager.Update(GameTime gameTime) in MatematikSpilMenu\ScreenManager.cs:line 101
       at Microsoft.Xna.Framework.Game.Update(GameTime gameTime)
       at Microsoft.Xna.Framework.Game.Tick()
       at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
       at Microsoft.Xna.Framework.GameHost.OnIdle()
       at Microsoft.Xna.Framework.WindowsGameHost.RunOneFrame()
       at Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e)
       at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Microsoft.Xna.Framework.WindowsGameHost.Run()
       at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
       at Microsoft.Xna.Framework.Game.Run()
       at MatematikSpilMenu.Program.Main() in MatematikSpilMenu\Game1.cs:line 120
  InnerException: System.Data.EntityCommandCompilationException
       Message=An error occurred while preparing the command definition. See the inner exception for details.
       Source=System.Data.Entity
       StackTrace:
            at System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
            at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues)
            at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
            at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
       InnerException: System.NotSupportedException
            Message=Server-generated keys and server-generated values are not supported by SQL Server Compact.
            Source=System.Data.SqlServerCe.Entity
            StackTrace:
                 at System.Data.SqlServerCe.SqlGen.DmlSqlGenerator.GenerateReturningSql(StringBuilder commandText, DbModificationCommandTree tree, ExpressionTranslator translator, DbExpression returning)
                 at System.Data.SqlServerCe.SqlGen.DmlSqlGenerator.GenerateInsertSql(DbInsertCommandTree tree, List`1& parameters, Boolean isLocalProvider)
                 at System.Data.SqlServerCe.SqlGen.SqlGenerator.GenerateSql(DbCommandTree tree, List`1& parameters, CommandType& commandType, Boolean isLocalProvider)
                 at System.Data.SqlServerCe.SqlCeProviderServices.CreateCommand(DbProviderManifest providerManifest, DbCommandTree commandTree)
                 at System.Data.SqlServerCe.SqlCeProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
                 at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
                 at System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree)
                 at System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
            InnerException: 

在我看来,问题的根源在于您使用的SQL server:

服务器不支持服务器生成的密钥和服务器生成的值 SQL Server Compact


您正在尝试在SQL server Compact版本上使用自动增量ID吗?我记不太清楚,但可能这在SQL版本中是不可能的。我建议您先检查一下。

找到了解决方案,似乎是数据库在使用太多地方时会出现bug(这只是我的猜测)。不管是哪种方式,创建一个新表,然后向其中添加内容似乎可以修复它(没有使用标识)。

根据我的经验,通常由db错误触发,在我的情况下,是与失败的表相关联的触发器引发了根异常。然而,在您的情况下,当使用自动编号(标识)时,您似乎错误地试图手动定义id字段。

在我的情况下,在打开表数据库后,自动链接列的主键问题消失了。

服务器生成的键性能不好,因此,请检查数据库可能是您的数据库主键是自动生成的键,因此,如果我们能够获得实际内部异常?什么是GameID?外键?是否有ID为1的游戏?GameID是我用于为相应游戏得出相应高分的ID。GameID=1用于告诉游戏应该从哪里取高分。但我会得到一个内部例外,你是否检查过高分表是否为空?Kamal,对不起,我不明白你想说什么=/你能重新措辞吗?问题是,它以前在表单上工作过。除非两者之间有区别?我不完全理解你。你是说同样的代码以前运行过一次?如果是的话,那么你必须检查一下自那以后你做了什么改变。从异常消息来看,问题似乎出在数据库上。你改变了它后面的数据库了吗?刚刚试着去掉ID上的自动增量,仍然给了我同样的错误。你的“db.HighScores”对象是否可能仍然试图将其作为标识处理?我不这么认为,因为我不得不删除它并重新插入,因为它一直给我错误,截图会有帮助吗?谢谢你让我想到触发器。我已经筋疲力尽了。
System.Data.UpdateException was unhandled
  Message=An error occurred while updating the entries. See the inner exception for details.
  Source=System.Data.Entity
  StackTrace:
       at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
       at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
       at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
       at System.Data.Objects.ObjectContext.SaveChanges()
       at MatematikSpilMenu.SaveBunniesSceen.SaveHighscore() in MatematikSpilMenu\SaveBunniesSceen.cs:line 173
       at MatematikSpilMenu.SaveBunniesSceen.Update(GameTime gameTime, Boolean otherScreenIsActive, Boolean coveredByOtherScreens) in C:\Users\Etarnalazure-Alien\documents\visual studio 2010\Projects\MatematikSpilMenu\MatematikSpilMenu\MatematikSpilMenu\SaveBunniesSceen.cs:line 110
       at MatematikSpilMenu.ScreenManager.Update(GameTime gameTime) in MatematikSpilMenu\ScreenManager.cs:line 101
       at Microsoft.Xna.Framework.Game.Update(GameTime gameTime)
       at Microsoft.Xna.Framework.Game.Tick()
       at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
       at Microsoft.Xna.Framework.GameHost.OnIdle()
       at Microsoft.Xna.Framework.WindowsGameHost.RunOneFrame()
       at Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e)
       at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Microsoft.Xna.Framework.WindowsGameHost.Run()
       at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
       at Microsoft.Xna.Framework.Game.Run()
       at MatematikSpilMenu.Program.Main() in MatematikSpilMenu\Game1.cs:line 120
  InnerException: System.Data.EntityCommandCompilationException
       Message=An error occurred while preparing the command definition. See the inner exception for details.
       Source=System.Data.Entity
       StackTrace:
            at System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
            at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues)
            at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
            at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
       InnerException: System.NotSupportedException
            Message=Server-generated keys and server-generated values are not supported by SQL Server Compact.
            Source=System.Data.SqlServerCe.Entity
            StackTrace:
                 at System.Data.SqlServerCe.SqlGen.DmlSqlGenerator.GenerateReturningSql(StringBuilder commandText, DbModificationCommandTree tree, ExpressionTranslator translator, DbExpression returning)
                 at System.Data.SqlServerCe.SqlGen.DmlSqlGenerator.GenerateInsertSql(DbInsertCommandTree tree, List`1& parameters, Boolean isLocalProvider)
                 at System.Data.SqlServerCe.SqlGen.SqlGenerator.GenerateSql(DbCommandTree tree, List`1& parameters, CommandType& commandType, Boolean isLocalProvider)
                 at System.Data.SqlServerCe.SqlCeProviderServices.CreateCommand(DbProviderManifest providerManifest, DbCommandTree commandTree)
                 at System.Data.SqlServerCe.SqlCeProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
                 at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
                 at System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree)
                 at System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
            InnerException: