admin管理员组

文章数量:1627945

目录

一、异常信息

二、异常原因

三、解决办法


一、异常信息

StorageServerInfoDal.cs::InsertStorageServerInfo()——StorageServer插入数据发生错误:System.Data.Entity.Infrastructure.DbUpdateException: 更新条目时出错。有关详细信息,请参阅内部异常。 ---> System.Data.Entity.Core.UpdateException: 更新条目时出错。有关详细信息,请参阅内部异常。 ---> System.Data.SQLite.SQLiteException: constraint failed
UNIQUE constraint failed: StorageServerInfo.Id
   在 System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)
   在 System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
   在 System.Data.SQLite.SQLiteDataReader.NextResult()
   在 System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
   在 System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
   在 System.Data.SQLite.SQLiteCommand.ExecuteNonQuery(CommandBehavior behavior)
   在 System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   在 System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
   在 System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues)
   在 System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
   --- 内部异常堆栈跟踪的结尾 ---
   在 System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
   在 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   在 System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
   在 System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
   在 System.Data.Entity.Internal.InternalContext.SaveChanges()
   --- 内部异常堆栈跟踪的结尾 ---
   在 System.Data.Entity.Internal.InternalContext.SaveChanges()
   在 KeenRayLargePC.PadDataAcessLayer.StorageServerInfoDal.InsertStorageServerInfo(List`1 StorageServerInfoList) 位置 D:\keenray6.2\trunk\code\iPads\PadDataAcessLayer\StorageServerInfoDal.cs:行号 40

二、异常原因

        主键ID没有设置自动加。首次更新的时候,默认ID == 0,可以成功。第二次更新的时候,ID还是默认等于0。导致ID重复,不能更新。下面是我操作的对象:   

  StorageServerInfo singleStorageServer = new StorageServerInfo()
            {
                StorageAE = "LWPACS001",
                LocalAE = "LamageAE001",
                StorageIP = "192.168.96.100",
                StoragePort = 45677,
                StorageExPress = "Default",
                StorageSendMode = 1,
                StorageFlag = 1,
                StorageAcknow = 1,
                StorageEmbed = 1,
                ConnectFlag = 0,
            };        
            storageServerList.Add(singleStorageServer);
            storageServerInfoDal.InsertStorageServerInfo(storageServerList);

三、解决办法

设置ID自增即可,如下所示:

本文标签: 详细信息异常基础SystemSqlite