microsoft / dotnet

This repo is the official home of .NET on GitHub. It's a great starting point to find many .NET OSS projects from Microsoft and the community, including many that are part of the .NET Foundation.
https://devblogs.microsoft.com/dotnet/
MIT License
14.38k stars 2.22k forks source link

Hello there! How to fix the error — The incoming tabular data stream (TDS) protocol stream is incorrect. The MARS TDS header contained errors? #1263

Open SergeyIlyinFirst opened 4 years ago

SergeyIlyinFirst commented 4 years ago

We encounter an error from time to time: The incoming tabular data stream (TDS) protocol stream is incorrect. The MARS TDS header contained errors. Tool versions: .net 4.8, sql server 13.0.5820.21. This problem is Microsoft. Data. SqlClient of all versions, and with System. Data. SqlClient 4.8.2. We tried all the solutions that are listed on the forums. Not help. Other developers also have this problem. Our users suffer from this. We sincerely ask you to pay attention to this problem as soon as possible and report a solution. Thanks!

mairaw commented 4 years ago

Seems like a duplicate of https://github.com/dotnet/SqlClient/issues/85

@cheenamalhotra

cheenamalhotra commented 4 years ago

Hi @SergeyIlyinFirst

Yes, this is a known issue and is tracked under https://github.com/dotnet/SqlClient/issues/85.

If you have a .NET Framework application, please try enabling below app context switch and let us know. (helpful info shared by a customer in https://github.com/dotnet/SqlClient/pull/547#issuecomment-716055128)

AppContext.SetSwitch("Switch.System.Data.SqlClient.MakeReadAsyncBlocking", true);

@mairaw could you please transfer this issue to dotnet/SqlClient repository? Thanks!

novitito commented 4 years ago

Hi, We exactly get this error yesterday too, on a running .net core App in production with no particular reason... If you can help us we are using Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.3"

Is there Something to update ou modify ? thanks David

cheenamalhotra commented 4 years ago

Hi @novitito

Please reference Microsoft.Data.SqlClient v1.1.3 or v2.0.1+ in your application to get fix (PR #557 and PR #550) for same issue in .NET Core applications.

If you continue to encounter issue with the updated driver, please wrap a repro application with latest driver version and provide us in Issue #85 in dotnet/sqlclient repository.

SergeyIlyinFirst commented 4 years ago

@cheenamalhotra AppContext.SetSwitch("Switch.System.Data.SqlClient.MakeReadAsyncBlocking", true) - not help. The error is repeated.

cheenamalhotra commented 4 years ago

@SergeyIlyinFirst

Let me clearly specify again as most information is in dotnet/sqlclient#85

For .NET Framework application:

If your application is using System.Data.SqlClient (.NET Framework), you need to use AppContext switch as under: AppContext.SetSwitch("Switch.System.Data.SqlClient.MakeReadAsyncBlocking", true);

whereas if you're using Microsoft.Data.SqlClient (.NET Framework), you need to use this AppContext switch: AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.MakeReadAsyncBlocking", true); (also set by default)

For .NET Core application:

Use System.Data.SqlClient v4.8.2, OR use Microsoft.Data.SqlClient v1.1.3 or above.

Could you please confirm what runtime your application is using and if trying above options are not working in your case?

cheenamalhotra commented 4 years ago

I'm not sure I follow 🤔

SergeyIlyinFirst commented 4 years ago

@cheenamalhotra we tested our app on a single server. The results in the pictures. There are fewer errors, but they are there. Testing other servers. There are options for the fix? Errors before correction 158, after 25. It should be zero. https://yadi.sk/d/wwOkoYjNG7U7Gw

SergeyIlyinFirst commented 4 years ago

@cheenamalhotra { "error": { "message": "The incoming tabular data stream (TDS) protocol stream is incorrect. The MARS TDS header contained errors.", "data": { "Errors": [{ "Source": ".Net SqlClient Data Provider", "Number": 4011, "State": 3, "Class": 16, "Server": "sqlintao", "Message": "The incoming tabular data stream (TDS) protocol stream is incorrect. The MARS TDS header contained errors.", "Procedure": "", "LineNumber": 1 }], "ClientConnectionId": "3fe3fc23-7d95-4320-96b3-16be93d81567", "ClassName": "System.Data.SqlClient.SqlException", "Message": "The incoming tabular data stream (TDS) protocol stream is incorrect. The MARS TDS header contained errors.", "Data": { "HelpLink.ProdName": "Microsoft SQL Server", "HelpLink.ProdVer": "13.00.5820", "HelpLink.EvtSrc": "MSSQLServer", "HelpLink.EvtID": "4011", "HelpLink.BaseHelpUrl": "http://go.microsoft.com/fwlink", "HelpLink.LinkId": "20476" }, "InnerException": null, "HelpURL": null, "StackTraceString": " at System.Data.SqlClient.SqlCommand.<>c.b180_0(Task1 result)\r\n at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke()\r\n at System.Threading.Tasks.Task.Execute()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Dapper.SqlMapper.d_33`1.MoveNext() in //Dapper/SqlMapper.Async.cs:line 419\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n", "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": "8\nb180_0\nSystem.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Data.SqlClient.SqlCommand+<>c\nSystem.Data.Common.DbDataReader b__180_0(System.Threading.Tasks.Task`1[System.Data.SqlClient.SqlDataReader])", "HResult": -2146232060, "Source": ".Net SqlClient Data Provider", "WatsonBuckets": null } } }