2010-03-17 66 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