當程序試圖訪問水果數據庫時遇到掛起。我已經在我的開發計算機和SQL Server服務器上啓用了網絡訪問MSDTC。與LINQ-SQL Server和TransactionScope掛起
代碼: (原諒代碼着色... SO曲解真實VB我.NET)
Using ts As New TransactionScope
Dim fruit As New FruitDataContext
Dim thingies As New ThingiesDataContext
If (From f In fruit.tblApples Where f.Rotten = "Yes" AndAlso f.batch = 1).Count >= 1 Then
'Record today's date as the day that the rotten apples were dumped.
End If
'Other complicated code that uses ThingiesDataContext and FruitDataContext
du.SubmitChanges()
ts.Complete()
End Using
編輯:
我周圍有點挖了,它原來的問題位於LINQ的行中。當我試圖與LINQ to SQL的展臺,以查看它,我得到以下錯誤:
System.InvalidCastException: Specified cast is not valid.
at LinqToSqlQueryVisualizer.SqlQueryInfo.deserialize(Stream stream)
at LinqToSqlQueryVisualizer.Visualizer.Display(IDialogVisualizerService windowService, Stream rawStream)
at LinqToSqlQueryVisualizer.DialogChooser.Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
at Microsoft.VisualStudio.DebuggerVisualizers.DebugViewerShim.ManagedShim.DelegatedHost.CreateViewer(IntPtr hwnd, HostServicesHelper hsh, SafeProxyWrapper proxy)
我還編輯了LINQ語句來接近我真正的代碼。
最終編輯: 我試着使用普通的SqlConnection而不是「thingies作爲新的ThingiesDataContext」,並且問題仍然存在。
似乎TransactionScope無法處理同一事務內的多個SQL連接。
微軟官方注意
parallel transactions are not supported by SQL Server.
從MSDN:http://msdn.microsoft.com/en-us/library/bb896149.aspx
是否有另一個事務持有打開另一個表?這是一個嵌套事務嗎? – 2010-03-17 01:47:49
否;沒有。 <填充器爲StackOverflow> – 2010-03-18 22:01:18