2010-03-17 28 views
0

當程序試圖訪問水果數據庫時遇到掛起。我已經在我的開發計算機和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

+0

是否有另一個事務持有打開另一個表?這是一個嵌套事務嗎? – 2010-03-17 01:47:49

+0

否;沒有。 <填充器爲StackOverflow> – 2010-03-18 22:01:18

回答

1

這不是一個MSDTC問題。如果是這樣,你會得到一個錯誤,說DTC沒有啓用,需要。這也不是死鎖問題,因爲你也會得到一個特定的錯誤。

如果我不得不猜測,我會說'其他複雜的代碼...'試圖執行數據庫操作並被一個或其他數據庫上下文對象阻止。

您可以確定的一種方法是運行SQL事件探查器以查看服務器上實際正在執行的SQL語句,並檢查塊。

+0

事實上,事實證明,LINQ線是造成這個問題。更多細節在我編輯的文章中。 – 2010-03-19 00:03:15