【问题标题】:The MARS TDS header contained errors - ASP.NET Core + EF Core 2.1.4 + Azure SQL ServerMARS TDS 标头包含错误 - ASP.NET Core + EF Core 2.1.4 + Azure SQL Server
【发布时间】:2019-03-14 12:58:44
【问题描述】:

我有一个 ASP.NET Core 应用程序 [Microsoft.AspNetCore.App 2.1.4] 和 EF Core 2.1.4 [已启用 DbContext 池],并且数据存储在 Azure SQL 数据库中。

偶尔 [1-2 天一次] 我收到不可恢复的错误,指出 System.Data.SqlClient.SqlException (0x80131904):传入的表格数据流 (TDS) 协议流不正确。 MARS TDS 标头包含错误。

一旦我重新启动应用程序,一切都会恢复工作,直到再次发生。

可能需要注意的是,我的连接字符串中根本没有启用 MultipleActiveResultSets,这使问题更加奇怪。

有没有其他人注意到类似的事情?有什么方法可以追踪问题吗?

堆栈跟踪:

System.Data.SqlClient.SqlException (0x80131904): The incoming tabular data stream (TDS) protocol stream is incorrect. The MARS TDS header contained errors.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.get_MetaData()
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementation[TState,TResult](Func`3 operation, Func`3 verifySucceeded, TState state)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Inviton.Web.Portal.Controllers.EventListController.GetEvents(BL bl, Int32 venueId, Int32 promoterId) 
   ---snip---

【问题讨论】:

  • 能否将以下内容添加到您的连接字符串中:MultipleActiveResultSets=False
  • 请查询以下 DMV (SELECT * FROM sys.dm_exec_connections) 你会惊讶地看到一些使用 MARS 的连接。
  • 您好 Alberto,我已经明确设置了 MultipleActiveResultSets=False,但仍然是一样的......我已经执行了您建议的查询。请问在哪里可以查看连接是否使用 MARS?
  • 请参阅本文档docs.microsoft.com/en-us/sql/relational-databases/…。阅读有关“net_transport”和“parent_connection_id”列的文档
  • 这是我收到的az687816.vo.msecnd.net/imgstore/… 根据文档中的描述,我认为目前没有任何连接使用 MARS,对吗?

标签: sql-server asp.net-core azure-sql-database entity-framework-core


【解决方案1】:

对于所有仍然面临此问题并最终出现在此页面上的人。

SqlCLient https://github.com/dotnet/SqlClient/issues/85 上有一个未解决的问题

截至今天尚未修复。

但是有一个hackaroud可以缓解它https://github.com/dotnet/SqlClient/issues/85#issuecomment-469432914

【讨论】:

【解决方案2】:

这对我有用:

右键单击您的项目 -> 管理 nuget 包 -> 更新。

将 Microsoft.Data.SqlClient 更新到最新版本。

【讨论】:

  • OP 使用的是 System.Data.SqlClient,而不是 Microsoft.Data.SqlClient。
  • 你是对的,但你没有注意到。我通过谷歌登陆这里,所以这可能对其有同样问题的其他人有所帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-08-31
  • 2017-05-27
  • 2019-05-15
  • 1970-01-01
  • 2017-01-23
  • 2021-07-12
  • 2017-03-28
相关资源
最近更新 更多