服务器无法恢复事务.LINQ到SQL

epi*_*isx 5 sql-server linq-to-sql

我收到一个System.Data.SqlClient.SqlException:服务器无法恢复该事务.描述:6c00000001执行Linq-To-SQL查询时.

这是我的存储库调用:

using (var ctx = new EntitiesDataContext())
{
    ctx.ObjectTrackingEnabled = false;
    ctx.DeferredLoadingEnabled = false;

    var loadOptions = new DataLoadOptions();
    loadOptions.LoadWith<Company2QualifierLicense>(n => n.QualifierLicense);
    loadOptions.LoadWith<Company2QualifierLicense>(n => n.Company);
    loadOptions.LoadWith<QualifierLicense>(n => n.QualifierLicenseHoldStatus);
    loadOptions.LoadWith<QualifierLicense>(n => n.LicenseTrade);
    loadOptions.LoadWith<Company>(n => n.CompanyHoldStatus);
    ctx.LoadOptions = loadOptions;

    return ctx.Company2QualifierLicenses.Where(p => p.QualifierLicense.QualifierLicenseNumber == qualifierLicense).ToList();
}
Run Code Online (Sandbox Code Playgroud)

这是生成的SQL:

-- Region Parameters
DECLARE @p0 VarChar(1000) = '11223344'
-- EndRegion
SELECT [t0].[CompanyID], [t0].[QualifierLicenseID], [t0].[InitiatedDate], [t0].[IsActive], [t0].[RowVersion], [t0].[LastUpdated], [t1].[QualifierLicenseID] AS [QualifierLicenseID2], [t1].[QualifierLicenseNumber], [t1].[LicenseTradeID], [t1].[LicenseExpirationDate], [t1].[FirstName], [t1].[LastName], [t1].[MailingAddress1], [t1].[MailingAddress2], [t1].[City], [t1].[StateAbbr], [t1].[ZIP], [t1].[Email], [t1].[Phone], [t1].[RowVersion] AS [RowVersion2], [t1].[LastUpdated] AS [LastUpdated2], [t3].[test], [t3].[LicenseTradeID] AS [LicenseTradeID2], [t3].[LicenseCode], [t3].[LicenseDescription], [t5].[QualifierLicenseHoldStatusID], [t5].[HoldReasonID], [t5].[QualifierLicenseID] AS [QualifierLicenseID3], [t5].[RowVersion] AS [RowVersion3], [t5].[LastUpdated] AS [LastUpdated3], (
    SELECT COUNT(*)
    FROM [frontdesk].[QualifierLicenseHoldStatus] AS [t6]
    WHERE [t6].[QualifierLicenseID] = [t1].[QualifierLicenseID]
    ) AS [value], [t4].[CompanyID] AS [CompanyID2], [t4].[EIN], [t4].[CompanyName], [t4].[MailingAddress1] AS [MailingAddress12], [t4].[MailingAddress2] AS [MailingAddress22], [t4].[City] AS [City2], [t4].[StateAbbr] AS [StateAbbr2], [t4].[ZIP] AS [ZIP2], [t4].[Email] AS [Email2], [t4].[Phone] AS [Phone2], [t4].[RowVersion] AS [RowVersion4], [t4].[LastUpdated] AS [LastUpdated4]
FROM [frontdesk].[Company2QualifierLicense] AS [t0]
INNER JOIN ([frontdesk].[QualifierLicense] AS [t1]
    LEFT OUTER JOIN (
        SELECT 1 AS [test], [t2].[LicenseTradeID], [t2].[LicenseCode], [t2].[LicenseDescription]
        FROM [frontdesk].[LicenseTrade] AS [t2]
        ) AS [t3] ON [t3].[LicenseTradeID] = [t1].[LicenseTradeID]) ON [t1].[QualifierLicenseID] = [t0].[QualifierLicenseID]
INNER JOIN [frontdesk].[Company] AS [t4] ON [t4].[CompanyID] = [t0].[CompanyID]
LEFT OUTER JOIN [frontdesk].[QualifierLicenseHoldStatus] AS [t5] ON [t5].[QualifierLicenseID] = [t1].[QualifierLicenseID]
WHERE [t1].[QualifierLicenseNumber] = @p0
ORDER BY [t0].[CompanyID], [t0].[QualifierLicenseID], [t1].[QualifierLicenseID], [t3].[LicenseTradeID], [t5].[QualifierLicenseHoldStatusID]
GO

-- Region Parameters
DECLARE @x1 Int = 241
-- EndRegion
SELECT [t0].[CompanyHoldStatusID], [t0].[CompanyID], [t0].[HoldReasonID], [t0].[RowVersion], [t0].[LastUpdated]
FROM [frontdesk].[CompanyHoldStatus] AS [t0]
WHERE [t0].[CompanyID] = @x1
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我在数据库查询后立即创建并处理DataContext,因此无法从调用方法进一步调用.

我发现向数据库发出了两个查询,我的猜测是,当向数据库发出第二个查询时,事务已经提交,但Linq-To-SQL应该比这更聪明.

我使用的是.NET 4.0和SQL Server 2008 R2(SP1) - 10.50.2789.0

有任何想法吗?

更新2011年12月21日

这是另一个例外: 此会话中活动的事务已由另一个会话提交或中止

更新2011年12月30日

一位同事发现此问题已报告给Microsoft,并且已被确认为错误,但不会修复,他们的建议是转移到实体框架.

epi*_*isx 0

一位同事发现这个问题已报告给微软,并已确认为错误,但不会修复,他们的建议是迁移到实体框架。