SQLite基础(六)System.Data.Entity.Infrastructure.DbUpdateException: 有关详细信息,请参阅内部异常。

目录

一、异常信息

二、异常原因

三、解决办法


一、异常信息

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自增即可,如下所示:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我爱AI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值