Repository navigation
Closed
Description
Copied from here:
I have an ASP.NET Core app [Microsoft.AspNetCore.App 2.1.4] with EF Core 2.1.4 [DbContext pooling enabled] and data stored on an Azure SQL database.
Occasionally [once in 1-2 days] I get unrecoverable error stating System.Data.SqlClient.SqlException (0x80131904): The incoming tabular data stream (TDS) protocol stream is incorrect. The MARS TDS header contained errors.
Once I restart the app, everything resumes working until it happens again.
Probably import to note is that I don't have MultipleActiveResultSets enabled in my connection string at all, which makes the issue even more strange.
Has anyone else noticed something similar? Are there any ways I can trace the problem?
Stack trace:
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)
Reacted by Andriy Svyryd, Jahmann82, michaeltnguyen, Michael Scrivo, NisseMain, Eugene Scully, KennethCaballero, Sepehr M, Isaac Duplan, Chris Sidi and 10 more
Reacted by David Klempfner
Metadata
Metadata
Assignees
Labels
No labels
Activity
brunolau commentedon Oct 10, 2018
Regarding the stackoverflow issue addiotional questions asked by Afsaneh:
Unfortunately can't post the csproj file contents...
I'm using EF Core 2.1.4 with Linq2Db provider (https://github.com/linq2db/linq2db.EntityFrameworkCore) for some of the queries that are poorly translated by the EF Core.., I'm however also referencing the System.Data.SqlClient 4.5.1 package in on of the solution's projects
I'm hosting on Azure Websites, so I assume it's some sort of IIS
I'll have to log this more explicitly. Is logging the "State" field sufficient for you ?
brunolau commentedon Oct 11, 2018
Here's the Dump of the SqlError object:
Class:
16
Errors:
System.Data.SqlClient.SqlError: The incoming tabular data stream (TDS) protocol stream is incorrect. The MARS TDS header contained errors.
Error code:
-2146232060
Line number:
1
Number:
4011
SQL Procedure:
None
Source:
Core .Net SqlClient Data Provider
State:
3
stap123 commentedon Dec 3, 2018
I had a random spate of these errors appear in my ASP.NET application today. I use ASP.NET Core 2.1, EF Core 2.1 and Azure SQL Database. They occurred in a small time window and once I stopped and started the web app the errors seemed to stop.
I think I queried successfully from SSMS while the errors were happening but couldn't say for sure that it was at the same time. If it happens again I'll query in SSMS to confirm that I can.
Is there anything I can provide that will help with a solution to this? (I have application insights and database logging turned on for my application)
NOTES:
MARS is explicitly set to off in my connection string (I use the one Azure Provides via the portal UI)
AfsanehR-zz commentedon Dec 3, 2018
@stap123 @brunolau Would you be able to provide us a minimal repro sample application? Thanks.
stap123 commentedon Dec 3, 2018
@afsanehr I wouldn't even know where to start, I've so far only seen it once today and restarting my application made it stop happening. I will keep my eyes open and if it starts happening in a pattern of some kind I'll try and put one together but at the moment it seems random so I've got no starting point for a repro.
I realise that's useless to you as well though haha
I have got about 130x exceptions logged in my App Insights at the moment but I doubt the stack trace would be enough for you?
It also looks like the error occurred on ALL queries no matter where they originated from so it doesn't appear to be a query specific issue.
brunolau commentedon Dec 4, 2018
I confirm the same - errors occurring at random queries, random time. I've tried to stress-test the application by running 30 threads that was making DB queries in parallel, but that didn't reproduce the issue either.
I've tried to use the SSMS query while the error was occurring and it worked, I've also tried to deploy to another azure release slot at the time the issue was occurring and it worked.
What I've temporarily ended up with was writing a middleware that once detects this particular error [based on the err message], automatically restarts the web app. As the issue occurs 1-2 times a day, it's acceptable, but much better would be having the issue solved.
What connects both mine and Adam's issue is the ASP.NET Core 2.1 + EF Core 2.1 + Azure SQL DB combo, but I cannot even say what part of the chain to blame.
AfsanehR-zz commentedon Dec 4, 2018
ok thanks @brunolau @stap123 . We will investigate this with the configurations you mentioned, although I think it would be highly unlikely we hit the same issue as we need to know what queries are running. Will get back to you on this. Could you also please give us the output of
dotnet --info?brunolau commentedon Dec 5, 2018
Here you go, obtained from the Azure console
.NET Core SDK (reflecting any global.json):
Version: 2.2.100
Commit: 51868761f2
Runtime Environment:
OS Name: Windows
OS Version: 10.0.14393
OS Platform: Windows
RID: win10-x86
Base Path: D:\Program Files (x86)\dotnet\sdk\2.2.100\
Host (useful for support):
Version: 2.2.0
Commit: 1249f08fed
.NET Core SDKs installed:
1.1.10 [D:\Program Files (x86)\dotnet\sdk]
2.1.403 [D:\Program Files (x86)\dotnet\sdk]
2.1.500 [D:\Program Files (x86)\dotnet\sdk]
2.2.100 [D:\Program Files (x86)\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.3 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.5 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.6 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.0 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.3 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.5 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.6 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.0 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.12 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.9 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.3 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.5 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.6 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
stap123 commentedon Dec 5, 2018
Here's mine 👍
.NET Core SDK (reflecting any global.json):
Version: 2.2.100
Commit: 51868761f2
Runtime Environment:
OS Name: Windows
OS Version: 10.0.14393
OS Platform: Windows
RID: win10-x86
Base Path: D:\Program Files (x86)\dotnet\sdk\2.2.100\
Host (useful for support):
Version: 2.2.0
Commit: 1249f08fed
.NET Core SDKs installed:
1.1.10 [D:\Program Files (x86)\dotnet\sdk]
2.1.403 [D:\Program Files (x86)\dotnet\sdk]
2.1.500 [D:\Program Files (x86)\dotnet\sdk]
2.2.100 [D:\Program Files (x86)\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.3 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.5 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.6 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.0 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.3 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.5 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.6 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.0 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.12 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.9 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.3 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.5 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.6 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
hackfaq commentedon Dec 7, 2018
Hello, we have experiensed same problem:
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.SqlCommand.<>c.b__122_0(Task
1 result) at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke()at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
--- End of stack trace from previous location where exception was thrown ---
at Dapper.SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command) in C:\projects\dapper\Dapper\SqlMapper.Async.cs:line 419
We use
How to reproduce:
When we experienced problem: our database log file was full, and we got exception: the transaction log for database '' is full due to "LOG_BACKUP", after that exception all queries in .net core app was with errors.
When we increased log file, .net 4.7 apps starts to work, but .net core app continue to throw exception. Only restart of application helped
stap123 commentedon Dec 10, 2018
I got this again this morning between 07:38:09 and 07:39:22.
Not sure if that's useful to help you track anything down or not. (I did nothing to any of my services to stop it happening but I then have successful requests being processed at 07:40:06)
brunolau commentedon Jan 4, 2019
I managed to temporarily auto-mitigate the issue by creating custom Entity framework execution strategy that once encounters the MARS error, closes the connection, clears the pool and reopens. Since I've introduced this workaround, I've been running errorless for 3 days.
To sum it up. Once the error is encountered, closing & reopening the error connection + clearing the connection pool seems to re-establish working order
PolitovArtyom commentedon Jan 5, 2019
We are getting the same problem.
Errors starts occuring in same moment on different servers. Application pool restart helps,
Application Server
Microsoft Windows Server 2012 R2 Standard 6.3.9600 Build 9600
dotnet host Version: 2.1.5 Commit: 290303f510
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore
Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore
Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Database
Microsoft SQL Server 2017 (RTM-CU11) (KB4462262) - 14.0.3038.14 (X64) Sep 14 2018 13:53:44 Copyright (C) 2017 Microsoft Corporation Enterprise Edition (64-bit) on Windows Server 2012 R2 Standard 6.3 (Build 9600: )
Application
Dapper 1.50.5
Microsoft.AspNetCore.App 2.1.5
sepehr1014 commentedon Feb 7, 2019
We're having the same issue. Any solutions?
PolitovArtyom commentedon Feb 8, 2019
@afsanehr
Do you need some additional data for investigation?
I can try to get application and tcp dump while errors occuring
228 remaining items
DavidKlempfner commentedon Sep 13, 2021
I'm getting this error too.
I'm using System.Data.SqlClient, and looks like the OP is too. But isn't https://github.com/dotnet for Microsoft.Data.SqlClient?
cheenamalhotra wrote above "Closing as issue has been fixed and backported to all versions" however is this for System.Data.SqlClient or Microsoft.Data.SqlClient?
I've submitted an issue here:
#1262
cheenamalhotra commentedon Sep 15, 2021
This repository only provides update to Microsoft.Data.SqlClient, however System.Data.SqlClient was updated with this fix too for v4.8.2. Please use v4.8.2+ to get this fix.
brewfreedom commentedon Mar 29, 2023
Just saw this in the wild running .net 4.8/SQL 2019/Server 2019 using system.data.sqlclient\4.8.5\runtimes\win\lib\netstandard2.0\System.Data.SqlClient.dll which is supposed to be fixed for this. Just recently installed KB5023702 and Servicing Stack 10.0.17763.4121 We are actually in the process of moving to microsoft.data.sqlclient/latest for all code. Assuming this is an entirely separate issue? Recycling the impacted application pool was the only way we were able to recover and assume at least for now mitigation would be ensure when we catch this to clear the pool for that connection? No reproduction code yet.
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.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.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest) at System.Data.SqlClient.TdsParser.GetDTCAddress(Int32 timeout, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlInternalConnectionTds.GetDTCAddress() at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx) at System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx) at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction) at System.Data.ProviderBase.DbConnectionPool.PrepareConnection(DbConnection owningObject, DbConnectionInternal obj, Transaction transaction) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource
1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)at System.Data.SqlClient.SqlConnection.Open()
Failing on both execute reader as well as opening connetions.
The incoming tabular data stream (TDS) protocol stream is incorrect. The MARS TDS header contained errors.
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.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, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
brewfreedom commentedon Mar 29, 2023
I think I missed the part where we need to also add MakeReadAsyncBlocking = true for .net framework clients. Can you guys confirm this bug is still possible with System.Data.SqlClient if we did not set that? Probably moot point since we are about to shift to Microsoft.Data.SqlClient.
rehman22 commentedon Oct 31, 2023
did any one fixed the issue ?
because i have same problem
DavidKlempfner commentedon Oct 31, 2023
@rehman22 See #85 (comment)
stephan-dantas commentedon Nov 3, 2023
I am currently using System.Data.SqlClient version 4.8.5 and facing the same issue.
nicksav commentedon Mar 3, 2024
Still have the same issue with System.Data.SqlClient version 4.8.6
JRahnama commentedon Mar 4, 2024
System.Data.SqlClient is currently in servicing mode and only receives security updates. To ensure you benefit from the latest updates and features, I highly recommend transitioning to Microsoft.Data.SqlClient.
Thorium commentedon Mar 4, 2024
This appeared as a new issue after patching System.Data.SqlClient to version 4.8.6. Must be some regression issue after the latest security fixes?
Thorium commentedon Jun 5, 2024
The real fix seems to be adding to your SQL connection string:
MultipleActiveResultSets=FalseI have no idea what it does, but whatever it is, it can't be worse than currently having random SQL connection failures in production.
Thorium commentedon Sep 25, 2024
It seems even "MultipleActiveResultSets=False" is not fixing this totally reliably.
ErikEJ commentedon Sep 25, 2024
@Thorium This issue is closed. I you encounter issues, I suggest create a new github issue with a runnable repro.
daiplusplus commentedon Jan 29, 2025
I'm experiencing this issue currently (i.e. my production deployment is on fire 🔥 right now, hurrah) in an Azure App Service on .NET Framework 4.8.x and am doing troubleshooting, and after having read this whole thread I have a question (and a half):
My contention is that, as I'm running in Azure App Service (though am unsure if it's 4.8.0 or 4.8.1), ostensibly updates/patches to the system-provided .NET Framework are all part of the service.
I checked the
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Data.dllfile, and its NTFS Last-Modified time was2023-11-30(which also roughly matches its PE header Build Date), which postdates the fix discussed above, so I assume the patch is included - but yet I'm still getting the MARS/TDS exception.UPDATE: I added a NuGet reference to
System.Data.SqlClientv4.9.0 (released 3 months ago: November 2024) in my project that previously had only referenced the in-box .NET Framework 4System.Dataassembly and after rebuilding and redeploying - and (somehow) re-triggering the same (or similar) application-wide query timeouts there doen't seem to be any sign of MARS/TDS errors, phew (but still plenty of Command-Timeout exceptions, hurrah, but at least that's something I can do something about).UPDATE2: Hmm, I am seeing logged SqlClient exceptions with stack-traces very similar to the MARS/TDS error but now they say "A severe error occurred on the current command. The results, if any, should be discarded." (which may-as-well be the same thing) but at least it seems like there's no widespread state corruption going on.
David-Engel commentedon Jan 30, 2025
@daiplusplus
There were two fixes for this issue in this repo (for Microsoft.Data.SqClient). The first fix was to ensure the MakeReadAsyncBlocking context switch was defaulted to true in MDS. This was ported to System.Data.SqlClient in .NET Core. (It is/was already true in System.Data.SqlClient in .NET Framework.) Is your app changing that App Context switch to false?
The second, later fix (which was very difficult to find) was to address this issue when MakeReadAsyncBlocking == false and then switch the default back to false (since it is a perf improvement). This fix was never ported to System.Data.SqlClient in either .NET Core or .NET Framework. I don't recommend running with MakeReadAsyncBlocking=false in SDS, as you may run into this issue under high load.
Regarding the NuGet reference to System.Data.SqlClient: If your app is targeting .NET Framework, it will still use the .NET Framework System.Data.SqlClient. The NuGet package just forwards to the .NET Framework implementation in that scenario. So that shouldn't make a difference.