我遇到鏈接到SQL和更新記錄的問題,我認爲問題是與當前事務的基礎上,我通過連接的數據上下文循環:LINQ到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(),錯誤是'新的事務是不允許的,因爲會話中有其他線程正在運行'。
你是否在第二次循環中得到錯誤? – ChrisF