当程序试图访问水果数据库时遇到挂起。我已经在我的开发计算机和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