Repository navigation
Description
Describe the bug
I am trying to upgrade an older ASP.NET app running on .Net Framework 4.8 to use Microsoft.Data.SqlClient. But when running the app after upgrading I run into errors early during startup. It is able to connect and make requests, but it fails on the forth connection that it makes.
It always fails on the same piece of code (a call to ExecuteScalar()), but if that code is run in isolation, then there are no problems.
Exception message: System.InvalidOperationException: Internal connection fatal error. Error state: 15, Token : 50
Stack trace: at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at Microsoft.Data.SqlClient.SqlDataReader.TryCloseInternal(Boolean closeReader)
at Microsoft.Data.SqlClient.SqlDataReader.Close()
at Microsoft.Data.SqlClient.SqlCommand.CompleteExecuteScalar(SqlDataReader reader, Boolean returnLastResult)
at Microsoft.Data.SqlClient.SqlCommand.ExecuteScalar()
at Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException) in /_/src/Microsoft/SqlServer/Management/ConnectionInfo/ConnectionManager.cs:line 808
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteScalar(String sqlCommand) in /_/src/Microsoft/SqlServer/Management/ConnectionInfo/ServerConnection.cs:line 1516
at Geomatic.Framework.Data.Impl.DbManagement.ExecuteScalar(String sql) in C:\dev\Development\src\Framework\app\Geomatic.Framework\Data\Impl\DbManagement.cs:line 111
at Geomatic.Framework.Data.Impl.DbManagement.ExecuteScalar[T](String sql) in C:\dev\Development\src\Framework\app\Geomatic.Framework\Data\Impl\DbManagement.cs:line 101
at Geomatic.Framework.Deployment.DbDeployment.GetVersionFromDatabase(ConnectionDef connectionDef) in C:\dev\Development\src\Framework\app\Geomatic.Framework\Deployment\DbDeployment.cs:line 316
at Geomatic.Framework.Deployment.DbDeployment.IsVersionCompatible(TimestampedDatabase timestampedDatabase, Boolean forRemovingObsoleteDatabases) in C:\dev\Development\src\Framework\app\Geomatic.Framework\Deployment\DbDeployment.cs:line 268
at Geomatic.Framework.Deployment.DbDeployment.<>c__DisplayClass19_0.<GetDatabaseSets>b__0(TimestampedDatabase x) in C:\dev\Development\src\Framework\app\Geomatic.Framework\Deployment\DbDeployment.cs:line 223
at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
at Geomatic.Framework.Deployment.DbDeployment.GetDatabaseSets(IList`1 databaseSetNames, Boolean forRemovingObsoleteDatabases) in C:\dev\Development\src\Framework\app\Geomatic.Framework\Deployment\DbDeployment.cs:line 221
at Geomatic.Framework.Deployment.DbDeployment.<GetLatestPrimaryDatabases>d__11.MoveNext() in C:\dev\Development\src\Framework\app\Geomatic.Framework\Deployment\DbDeployment.cs:line 77
at Geomatic.Framework.Deployment.WebDbDeployment.UpdateCurrentWebAppConnectionStrings()
at Geomatic.Framework.Deployment.WebDbDeployment.UpdateWebAppConnectionStrings()
at Geomatic.MosaicProspect.GlobalAsax.Application_Start(Object sender, EventArgs e)]
To reproduce
I do not have a minimal way of reproducing this issue without sending over a lot of code and databases.
I am hoping to find some way of creating a smaller reproducible example, but I am not sure what causes the problem, so it is hard to construct it. Any input would be appreciated.
Expected behavior
I expected it the code to work in a similar fashion to System.Data.SqlClient, or at least get an exception with a helpful message that can be used for debugging. The error that I get leads nowhere and it is very hard for me to know where to look and what to change.
Further technical details
Microsoft.Data.SqlClient version: (found on the nuget or Microsoft.Data.SqlClient.dll)
.NET target: .NET Framework 4.8
SQL Server version: SQL Server 2016
Operating system: Windows 11 client calling the server
Additional context
Connection string is in this format: Data Source=SERVER_NAME;Initial Catalog=DB_NAME;Integrated Security=True;Pooling=False;Encrypt=False (I have also tried without the Pooling=False, it still fails the same way)
Here is the logged output of diagnostics tracing:
2026-05-20 12:44:07,533 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionOpenBefore]: [OperationId, 98d0b7aa-74c7-460e-beb1-c20b690501b4], [Operation, Open], [Timestamp, 1576111278735], [Connection, Microsoft.Data.SqlClient.SqlConnection], [ClientVersion, 7.0.1.26114]
2026-05-20 12:44:07,912 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionOpenAfter]: [OperationId, 98d0b7aa-74c7-460e-beb1-c20b690501b4], [Operation, Open], [Timestamp, 1576115231063], [ConnectionId, 20931833-8f54-420d-932e-e6a7c3eae471], [Connection, Microsoft.Data.SqlClient.SqlConnection], [ClientVersion, 7.0.1.26114], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:07,951 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandBefore]: [OperationId, 245ce2e6-f9f2-4024-9b55-0c04f07db71d], [Operation, ExecuteReader], [Timestamp, 1576115720932], [ConnectionId, 20931833-8f54-420d-932e-e6a7c3eae471], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand]
2026-05-20 12:44:08,083 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandAfter]: [OperationId, 245ce2e6-f9f2-4024-9b55-0c04f07db71d], [Operation, ExecuteReader], [Timestamp, 1576116743162], [ConnectionId, 20931833-8f54-420d-932e-e6a7c3eae471], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:08,121 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionCloseBefore]: [OperationId, 3b8ba6d0-1346-4f89-a156-267448c9940a], [Operation, Close], [Timestamp, 1576117337187], [ConnectionId, 20931833-8f54-420d-932e-e6a7c3eae471], [Connection, Microsoft.Data.SqlClient.SqlConnection], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:08,131 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionCloseAfter]: [OperationId, 3b8ba6d0-1346-4f89-a156-267448c9940a], [Operation, Close], [Timestamp, 1576117443033], [ConnectionId, 20931833-8f54-420d-932e-e6a7c3eae471], [Connection, Microsoft.Data.SqlClient.SqlConnection], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:08,139 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionOpenBefore]: [OperationId, 62f03a5b-47ee-454a-8727-9cd8509f6c49], [Operation, Open], [Timestamp, 1576117556101], [Connection, Microsoft.Data.SqlClient.SqlConnection], [ClientVersion, 7.0.1.26114]
2026-05-20 12:44:08,139 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionOpenAfter]: [OperationId, 62f03a5b-47ee-454a-8727-9cd8509f6c49], [Operation, Open], [Timestamp, 1576117593438], [ConnectionId, 20931833-8f54-420d-932e-e6a7c3eae471], [Connection, Microsoft.Data.SqlClient.SqlConnection], [ClientVersion, 7.0.1.26114], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:08,139 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandBefore]: [OperationId, f8f941ae-fc97-4b12-b765-c5ce24ecfeea], [Operation, ExecuteReader], [Timestamp, 1576117615849], [ConnectionId, 20931833-8f54-420d-932e-e6a7c3eae471], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand]
2026-05-20 12:44:08,202 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandAfter]: [OperationId, f8f941ae-fc97-4b12-b765-c5ce24ecfeea], [Operation, ExecuteReader], [Timestamp, 1576118158488], [ConnectionId, 20931833-8f54-420d-932e-e6a7c3eae471], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:08,202 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionCloseBefore]: [OperationId, 7358b529-bdd8-49ae-852f-46e3115acff0], [Operation, Close], [Timestamp, 1576118224736], [ConnectionId, 20931833-8f54-420d-932e-e6a7c3eae471], [Connection, Microsoft.Data.SqlClient.SqlConnection], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:08,202 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionCloseAfter]: [OperationId, 7358b529-bdd8-49ae-852f-46e3115acff0], [Operation, Close], [Timestamp, 1576118250841], [ConnectionId, 20931833-8f54-420d-932e-e6a7c3eae471], [Connection, Microsoft.Data.SqlClient.SqlConnection], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:08,218 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionOpenBefore]: [OperationId, 0d5abfe5-93bb-4de2-9c82-0dab5b438fd4], [Operation, Open], [Timestamp, 1576118411991], [Connection, Microsoft.Data.SqlClient.SqlConnection], [ClientVersion, 7.0.1.26114]
2026-05-20 12:44:08,279 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionOpenAfter]: [OperationId, 0d5abfe5-93bb-4de2-9c82-0dab5b438fd4], [Operation, Open], [Timestamp, 1576118999287], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [Connection, Microsoft.Data.SqlClient.SqlConnection], [ClientVersion, 7.0.1.26114], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:08,316 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandBefore]: [OperationId, 2ded8a06-8cf0-4f03-a38b-5712091785e9], [Operation, ExecuteReader], [Timestamp, 1576119336915], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand]
2026-05-20 12:44:08,324 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandAfter]: [OperationId, 2ded8a06-8cf0-4f03-a38b-5712091785e9], [Operation, ExecuteReader], [Timestamp, 1576119385308], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:08,453 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandBefore]: [OperationId, e48f4fa4-4dea-43a1-b0db-81409f5907c9], [Operation, ExecuteScalar], [Timestamp, 1576120772614], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand]
2026-05-20 12:44:08,479 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandAfter]: [OperationId, e48f4fa4-4dea-43a1-b0db-81409f5907c9], [Operation, ExecuteScalar], [Timestamp, 1576120906669], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:08,644 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandBefore]: [OperationId, 26654182-8023-4dbd-9183-5c77d9c1a962], [Operation, ExecuteReader], [Timestamp, 1576122582579], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand]
2026-05-20 12:44:08,685 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandAfter]: [OperationId, 26654182-8023-4dbd-9183-5c77d9c1a962], [Operation, ExecuteReader], [Timestamp, 1576122954784], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:08,880 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandBefore]: [OperationId, 6915fba9-3868-45f7-bc54-5ccf8ee1b215], [Operation, ExecuteScalar], [Timestamp, 1576124933736], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand]
2026-05-20 12:44:08,886 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandAfter]: [OperationId, 6915fba9-3868-45f7-bc54-5ccf8ee1b215], [Operation, ExecuteScalar], [Timestamp, 1576124985343], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:08,898 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandBefore]: [OperationId, 189eaa8a-610b-4c91-a4a3-fc16857e0e4e], [Operation, ExecuteReader], [Timestamp, 1576125124667], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand]
2026-05-20 12:44:08,907 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandAfter]: [OperationId, 189eaa8a-610b-4c91-a4a3-fc16857e0e4e], [Operation, ExecuteReader], [Timestamp, 1576125191594], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:08,951 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandBefore]: [OperationId, 8cd248f2-04cd-4cec-9710-88d592a6537c], [Operation, ExecuteReader], [Timestamp, 1576125785922], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand]
2026-05-20 12:44:08,966 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandAfter]: [OperationId, 8cd248f2-04cd-4cec-9710-88d592a6537c], [Operation, ExecuteReader], [Timestamp, 1576125897948], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:08,994 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandBefore]: [OperationId, 0d5f401f-d008-467c-ae8a-eed4016189b3], [Operation, ExecuteNonQuery], [Timestamp, 1576126086973], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand]
2026-05-20 12:44:09,003 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandAfter]: [OperationId, 0d5f401f-d008-467c-ae8a-eed4016189b3], [Operation, ExecuteNonQuery], [Timestamp, 1576126150329], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:09,004 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandBefore]: [OperationId, ea1b8540-9be6-40a9-ad3f-73a737597d3f], [Operation, ExecuteReader], [Timestamp, 1576126175309], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand]
2026-05-20 12:44:09,012 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandAfter]: [OperationId, ea1b8540-9be6-40a9-ad3f-73a737597d3f], [Operation, ExecuteReader], [Timestamp, 1576126288953], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:09,044 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionCloseBefore]: [OperationId, ff9f7fac-962e-4a55-b29c-21021479b611], [Operation, Close], [Timestamp, 1576126695944], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [Connection, Microsoft.Data.SqlClient.SqlConnection], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:09,044 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionCloseAfter]: [OperationId, ff9f7fac-962e-4a55-b29c-21021479b611], [Operation, Close], [Timestamp, 1576126725543], [ConnectionId, e2b83a6e-ea16-4b9e-96b1-1270806baf10], [Connection, Microsoft.Data.SqlClient.SqlConnection], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:09,060 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionOpenBefore]: [OperationId, 84116a96-a81a-4879-8d8f-5fa76140dcd7], [Operation, Open], [Timestamp, 1576126740560], [Connection, Microsoft.Data.SqlClient.SqlConnection], [ClientVersion, 7.0.1.26114]
2026-05-20 12:44:09,091 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionOpenAfter]: [OperationId, 84116a96-a81a-4879-8d8f-5fa76140dcd7], [Operation, Open], [Timestamp, 1576127076320], [ConnectionId, 321c1e95-0c4e-4379-938f-68063da2d0c0], [Connection, Microsoft.Data.SqlClient.SqlConnection], [ClientVersion, 7.0.1.26114], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:09,091 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandBefore]: [OperationId, e52e10f9-2ab7-434f-844e-9cabc8a5e034], [Operation, ExecuteScalar], [Timestamp, 1576127094955], [ConnectionId, 321c1e95-0c4e-4379-938f-68063da2d0c0], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand]
2026-05-20 12:44:09,107 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionCloseBefore]: [OperationId, 70252906-72dd-4e30-83c5-e6311aabb8af], [Operation, Close], [Timestamp, 1576127264744], [ConnectionId, 321c1e95-0c4e-4379-938f-68063da2d0c0], [Connection, Microsoft.Data.SqlClient.SqlConnection], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:09,107 [1] INFO Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteConnectionCloseAfter]: [OperationId, 70252906-72dd-4e30-83c5-e6311aabb8af], [Operation, Close], [Timestamp, 1576127286640], [ConnectionId, 321c1e95-0c4e-4379-938f-68063da2d0c0], [Connection, Microsoft.Data.SqlClient.SqlConnection], [Statistics, Microsoft.Data.SqlClient.SqlStatistics+StatisticsDictionary]
2026-05-20 12:44:14,012 [1] ERROR Geomatic.Framework.Data.Logging.SqlClientDiagnosticTracing [(null)] - SqlClient [Microsoft.Data.SqlClient.WriteCommandError]: [OperationId, e52e10f9-2ab7-434f-844e-9cabc8a5e034], [Operation, ExecuteScalar], [Timestamp, 1576161247039], [ConnectionId, 321c1e95-0c4e-4379-938f-68063da2d0c0], [TransactionId, ], [Command, Microsoft.Data.SqlClient.SqlCommand], [Exception, System.InvalidOperationException: Internal connection fatal error. Error state: 15, Token : 50
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at Microsoft.Data.SqlClient.SqlDataReader.TryCloseInternal(Boolean closeReader)
at Microsoft.Data.SqlClient.SqlDataReader.Close()
at Microsoft.Data.SqlClient.SqlCommand.CompleteExecuteScalar(SqlDataReader reader, Boolean returnLastResult)
at Microsoft.Data.SqlClient.SqlCommand.ExecuteScalar()
at Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException) in /_/src/Microsoft/SqlServer/Management/ConnectionInfo/ConnectionManager.cs:line 808
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteScalar(String sqlCommand) in /_/src/Microsoft/SqlServer/Management/ConnectionInfo/ServerConnection.cs:line 1516
at Geomatic.Framework.Data.Impl.DbManagement.ExecuteScalar(String sql) in C:\dev\Development\src\Framework\app\Geomatic.Framework\Data\Impl\DbManagement.cs:line 111
at Geomatic.Framework.Data.Impl.DbManagement.ExecuteScalar[T](String sql) in C:\dev\Development\src\Framework\app\Geomatic.Framework\Data\Impl\DbManagement.cs:line 101
at Geomatic.Framework.Deployment.DbDeployment.GetVersionFromDatabase(ConnectionDef connectionDef) in C:\dev\Development\src\Framework\app\Geomatic.Framework\Deployment\DbDeployment.cs:line 316
at Geomatic.Framework.Deployment.DbDeployment.IsVersionCompatible(TimestampedDatabase timestampedDatabase, Boolean forRemovingObsoleteDatabases) in C:\dev\Development\src\Framework\app\Geomatic.Framework\Deployment\DbDeployment.cs:line 268
at Geomatic.Framework.Deployment.DbDeployment.<>c__DisplayClass19_0.<GetDatabaseSets>b__0(TimestampedDatabase x) in C:\dev\Development\src\Framework\app\Geomatic.Framework\Deployment\DbDeployment.cs:line 223
at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
at Geomatic.Framework.Deployment.DbDeployment.GetDatabaseSets(IList`1 databaseSetNames, Boolean forRemovingObsoleteDatabases) in C:\dev\Development\src\Framework\app\Geomatic.Framework\Deployment\DbDeployment.cs:line 221
at Geomatic.Framework.Deployment.DbDeployment.<GetLatestPrimaryDatabases>d__11.MoveNext() in C:\dev\Development\src\Framework\app\Geomatic.Framework\Deployment\DbDeployment.cs:line 77
at Geomatic.Framework.Deployment.WebDbDeployment.UpdateCurrentWebAppConnectionStrings()
at Geomatic.Framework.Deployment.WebDbDeployment.UpdateWebAppConnectionStrings()
at Geomatic.MosaicProspect.GlobalAsax.Application_Start(Object sender, EventArgs e)]
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn progress
Activity
[-]"Internal connection fatal error" from[/-][+]"Internal connection fatal error" from TdsParser.TryRun[/+]github-actions commentedon May 20, 2026
🔍 Triage Summary
Area\NetfxSystem.Data.SqlClientwith a different token and a different root cause)System.Data.SqlClient— worked previously, fails after migration toMicrosoft.Data.SqlClientAnalysis
The reporter is migrating an ASP.NET app from
System.Data.SqlClienttoMicrosoft.Data.SqlClient7.0.1 on .NET Framework 4.8. The errorSystem.InvalidOperationException: Internal connection fatal error. Error state: 15, Token : 50is thrown insideTdsParser.TryRunduringSqlDataReader.Close()/CompleteExecuteScalar, but only when multiple connections are made in sequence during application startup (specifically the 4th connection). Pooling is disabled, the connection uses Integrated Security against SQL Server 2016, and the issue does not reproduce in isolation. This points to a TDS state machine issue specific to the .NET Framework code path, possibly related to howTdsParserhandles token 50 (an unknown/unexpected TDS token during reader cleanup). Severity: P2 — application startup is blocked after migration.Next Steps
7.0.1or7.0.0) so we can check changelogs for any related fixes.TdsParser.TryRunon the .NET Framework code path — specifically how TDS token0x32(decimal 50) is handled duringSqlDataReader.TryCloseInternal. The fact that it only occurs on the 4th connection in a sequence (even withPooling=False) may suggest shared parser/session state or a login-token negotiation side-effect in the.netfxpath that differs fromSystem.Data.SqlClient. The agent should also check whether SQL Server 2016 sends any login-response tokens that the newer driver doesn't expect or handle correctly.netsh trace) or enableSqlClientDiagnosticTracingat TRACE level to capture what token is received just before the error.initram commentedon May 20, 2026
I am using Microsoft.Data.SqlClient version 7.0.1 from nuget.
dallmair commentedon May 20, 2026
Same here, both 7.0.0 and 7.0.1 on .NET 4.8 fail this way, haven't tried older versions. Tried to connect to both SQL Server 2019 as well as SQL Server 2025.
cheenamalhotra commentedon May 26, 2026
@initram @dallmair
From the traces, it seems like your application is sharing physical connection across multiple commands. The trace reveals activity on the connection
321c1e95-0c4e-4379-938f-68063da2d0c0:WriteConnectionOpenAfterat timestamp 1576127076320WriteCommandBefore(ExecuteScalar) at 1576127094955WriteConnectionCloseBeforeat 1576127264744 — the connection is being closed while the command is still in progressWriteCommandErrorat 1576161247039 — the error fires ~5 seconds laterThe connection is being closed underneath the active command. This is the classic symptom of
Microsoft.SqlServer.Management.Common.ServerConnectionsharing a single physical SqlConnection across multiple logical operations, where one code path closes the connection while another is still reading results.Here's what I would recommend:
initram commentedon May 27, 2026
What worked was downgrading to Microsoft.Data.SqlClient 6.1.5. I can not provide a new diagnostics trace for this version as it does not support it for .Net Framework (as far as I can tell)
So my code works with System.Data.SqlClient and it works with Microsoft.Data.SqlClient 6.1.5, but it does not work with Microsoft.Data.SqlClient 7.0.1.
Thanks for helping with this. I will gladly try a new version of 7.x.x, if any fixes are released related to this in the future.
initram commentedon May 27, 2026
What I think is happening with the trace with connection id 321c1e95-0c4e-4379-938f-68063da2d0c0 is that it fails during the command (after WriteCommandBefore, but before WriteCommandAfter) but the tracing does not log the error event before the connection has been closed. I think the connection is being closed as it failed communication and then logged error afterwards.
I have not looked at the code, but that is what I assume has happened.
dallmair commentedon Jun 9, 2026
Hi @cheenamalhotra and also @initram, thanks for following up. Sorry for the late response from my side, I was oof for a few days.
Just like @initram, I can also confirm it's a regression in 7.0.0 as 6.1.5 works fine. Digging through the code base of the internal tool I'm encountering this with, I checked every connection instantiation and usage, but everything is fine and disposed of correctly with
usingblocks and statements, every connection, transaction, command, reader, etc.So I've tried to create a minimal reproduction today, and it isn't as easy as it seems. Interestingly, I can run everything just fine in a .NET 4.8 Console App (with 7.0.1), but when I use the exact same code in an ASP.NET 4.8 app hosted in IIS it fails. As there is
at Geomatic.MosaicProspect.GlobalAsax.Application_Startin the stack trace posted by @initram in the initial report, it looks like that's the case for both of us.Maybe that helps anyone in the team to root cause this and come up with a fix?
initram commentedon Jun 9, 2026
I am also in an asp.net app as you noticed.
1 remaining item
mdaigle commentedon Oct 1, 2026
@initram @dallmair our theory at the moment is that your application is triggering a ThreadAbortException mid-command. In our testing, manually triggering a ThreadAbortException during ExecuteScalar results in the same stack trace and error message. We suspect that a change introduced in #3535 removed some cleanup we used to do when encountering ThreadAbort, OOM, etc. Now, a close run in a finally statement encounters partial state and fails, obscuring the underlying error. I'll work on a fix for the cleanup so that the proper exception is exposed.
In the meantime, if you can temporarily register an
AppDomain.CurrentDomain.FirstChanceExceptionhandler it will help pinpoint the cause of the underlying exception. You can add it at the very beginning ofApplication_Start, before the first database operation.For example:
initram commentedon Oct 5, 2026
Thanks @mdaigle, and sorry for the slow reply.
I added the FirstChanceException handler at the very beginning of Application_Start, before the first database operation, and retried with Microsoft.Data.SqlClient 7.0.1. It's the same build as in my original trace (7.0.1.26114), again on .NET Framework 4.8 under IIS (Express).
I can no longer reproduce the error. Startup now runs the same code path as the original stack trace (DbDeployment.GetVersionFromDatabase → SMO ServerConnection.ExecuteScalar). It also rewrites a config file mid-startup, which recycles the AppDomain. That all completes, and the app restarts, lets me sign in and serves pages normally. The handler caught no ThreadAbortException and no SqlClient exceptions, only the usual assembly-probing noise.
Several things have changed since May, so I can't say which one made the difference:
If the cause was on our side, one possibility is that an exception was thrown during the command that wasn't a ThreadAbortException, for example a FileLoadException from a mismatched binding redirect, and that the cleanup issue you describe hid it the same way. I can't confirm this, because I no longer have that exact dependency graph or server state.
I think your fix for surfacing the underlying exception is still well worth doing. "Internal connection fatal error. Error state: 15, Token : 50" gave us nothing to go on, and @dallmair may still be running into it. If it comes back for us, I'll post the handler output here.
MaceWindu commentedon Oct 12, 2026
We see the same failure on Microsoft.Data.SqlClient 7.0.2, on .NET 10, against SQL Server 2019, in a Windows service. Our case differs from the original report in two ways: the token is 49, and the path is async (an
IAsyncEnumerablequery through linq2db 6.5.0). The exception comes out of the reader's dispose, not out of a read:The calling code is roughly this:
So the reader is disposed in one of three ways: after reading every row, after an early
returnfrom the loop, or after an exception or cancellation. Token 49 (0x31) is not a valid TDS token, so the parser state was already broken whenClose()tried to drain the rest of the response. That fits the theory that cleanup no longer happens after an aborted operation (#3535), with dispose hiding the original exception. Here the aborting event would be async cancellation or a connection fault rather than aThreadAbortException, which doesn't exist on .NET Core.In our logs the early-exit branch did not run, and nothing else failed first: no timeout, no cancellation, no earlier exception on the same operation. The whole thing took about 30 ms, from opening the transaction (a fresh connection from the pool) to the error. So either the dispose error hides an exception thrown inside the loop body, or the connection was already in a bad state when it came out of the pool.
We have not reproduced it on demand; it is a single occurrence in production logs.