An error occurred while updating records. See Internal Exception for more details. - Linq to Entity

looked around and I just can’t understand what’s wrong.

I'm currently trying to update my database with a new high when ever a player dies. But he continues to throw this exception on me, no matter what I want to try and save.

the code:

HighScore hs = new HighScore(); var id = from i in db.HighScores orderby i.ID descending select i; int newId = 0; if (id.Count() == 0) { newId = 1; } else { newId = id.First().ID + 1; } hs.ID = 6; //I just hardcoded in 6 to make sure i wasent because of the newId //thing, and i have checked if theres already something on the sixths spot as well. hs.UserHighscore = 100; hs.HighscoreUsername = "test"; hs.GameID = 1; db.HighScores.AddObject(hs); db.SaveChanges(); 

I checked again and again and I just can't figure out what the problem is.

Any help would be assigned.

An exception:

 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: 
+6
source share
6 answers

It seems to me that the root of the problems is on the used SQL server:

Server keys and server-generated values ​​are not supported by SQL Server Compact.

Are you trying to use the auto increment identifier on the compact version of SQL Server? I don’t remember very well, but perhaps this is not possible with this version of SQL. I suggest you check this out first.

+4
source

Well, from my experience, which usually works when db fails, in my case it was a trigger related to a table that failed and threw a root exception. In your case, however, it seems that you are mistakenly trying to determine the identifier manually when using the field with automatic numbering (identification).

+5
source

Found a solution, it looks like its database, which could be mistaken if too many places are used (this is only I guess). In any case, creating a new table and then adding things there seemed to fix it (did not use Identity.)

+1
source

In my case, after including the table database, the primary key in the auto_ink column the problem disappeared.

0
source

The keys generated by the server do not work properly, so go and check if the database database ur database can be automatically generated, so try to insert the data manually.

0
source

Also check the relationships between the tables.

0
source

Source: https://habr.com/ru/post/917621/


All Articles