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.
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.
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.
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
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)]
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.
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: