[研究]System.Data.Entity.Core.OptimisticConcurrencyException 處理並行衝突 (EF6)
2025-04-21
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 19
********************************************************************************
System.Data.Entity.Core.OptimisticConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions. System.Data.Entity.Infrastructure.DbUpdateConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions. ---> System.Data.Entity.Core.OptimisticConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions. 於 System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.ValidateRowsAffected(Int64 rowsAffected, UpdateCommand source) 於 System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() 於 System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<>c.<Update>b__21_0(UpdateTranslator ut) 於 System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult, Func`2 updateFunction) 於 System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update() 於 System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__153_0() 於 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.<>c__DisplayClass148_0.<SaveChangesInternal>b__0() 於 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation) 於 System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction) 於 System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options) 於 System.Data.Entity.Internal.InternalContext.SaveChanges() --- 內部例外狀況堆疊追蹤的結尾 --- 於 System.Data.Entity.Internal.InternalContext.SaveChanges() 於 System.Data.Entity.Internal.LazyInternalContext.SaveChanges() 於 System.Data.Entity.DbContext.SaveChanges() 於 System.Web.Providers.DefaultSessionStateProvider.ReleaseItemExclusive(HttpContext context, String id, Object lockId) 於 System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) 於 System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 於 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) 於 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) |
********************************************************************************
處理並行衝突 (EF6)
http://go.microsoft.com/fwlink/?LinkId=472540
https://learn.microsoft.com/zh-tw/ef/ef6/saving/concurrency?redirectedfrom=MSDN
Handling Concurrency Conflicts (EF6)
https://learn.microsoft.com/en-us/ef/ef6/saving/concurrency?redirectedfrom=MSDN
OptimisticConcurrencyException 類別
https://learn.microsoft.com/zh-tw/dotnet/api/system.data.optimisticconcurrencyexception?view=netframework-4.8.1
發生開放式同步存取違規時擲回的例外狀況。
https://learn.microsoft.com/en-us/dotnet/api/system.data.optimisticconcurrencyexception?view=netframework-4.8.1
The exception that is thrown when an optimistic concurrency violation occurs.
********************************************************************************
(完)
相關