我在链接到 SQL 和更新记录时遇到问题,我认为问题出在当前事务上,因为我正在循环访问连接的数据上下文:
Using db = New PostcodeLookupModelContainer()
Dim Stores = From b In db.lkpStores Where b.storeId ' = iStoreID ' Order By b.storeId
For Each store In Stores
Debug.Print(store.StorePostcode)
Dim newStore As New lkpStores()
newStore.depotId = store.depotId
newStore.StorePostcode = store.StorePostcode
newStore.depotId = store.depotId
newStore.DepotDistance = store.DepotDistance
db.lkpStores.Attach(newStore)
newStore.DepotDistance = 50
db.SaveChanges()
Next store
End Using
我收到错误时的行是 db.SaveChanges() 并且错误是“不允许新事务,因为会话中还有其他线程正在运行。”