It occurs randomly only for Async operations (e.g. ExecuteNonQueryAsync). I couldn't reproduce the error on the local machine (windows), so it may be linux related, but I can't confirm it.
In short - I want to insert records according to the DataTable. I open a connection (async), add a command, parameters and call ExecuteNonQueryAsync. Randomly, an error occurs "System.InvalidOperationException: Invalid operation. The connection is closed."
System.InvalidOperationException: Invalid operation. The connection is closed.
at System.Data.SqlClient.TdsParserStateObject.WritePacket(Byte flushMode, Boolean canAccumulate)
at System.Data.SqlClient.TdsParser.WriteLong(Int64 v, TdsParserStateObject stateObj)
at Microsoft.SqlServer.Server.ValueUtilsSmi.SetCompatibleValue(SmiEventSink_Default sink, ITypedSettersV3 setters, Int32 ordinal, SmiMetaData metaData, Object value, ExtendedClrTypeCode typeCode, Int32 offset)
at Microsoft.SqlServer.Server.ValueUtilsSmi.SetDataTable_Unchecked(SmiEventSink_Default sink, SmiTypedGetterSetter setters, Int32 ordinal, SmiMetaData metaData, DataTable value)
at System.Data.SqlClient.TdsParser.WriteSmiParameter(SqlParameter param, Int32 paramIndex, Boolean sendDefault, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc, Boolean sync, TaskCompletionSource`1 completion, Int32 startRpc, Int32 startParam)
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.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
at System.Data.SqlClient.SqlCommand.BeginExecuteNonQuery(AsyncCallback callback, Object stateObject)
Related #54 - Should currently be fixed but it doesn't seem to be #796
It occurs randomly only for Async operations (e.g. ExecuteNonQueryAsync). I couldn't reproduce the error on the local machine (windows), so it may be linux related, but I can't confirm it.
In short - I want to insert records according to the DataTable. I open a connection (async), add a command, parameters and call ExecuteNonQueryAsync. Randomly, an error occurs "System.InvalidOperationException: Invalid operation. The connection is closed."
Further technical details
Package: System.Data.SqlClient version: 4.8.3
.NET target: net6.0
SQL Server version: Microsoft SQL Azure (RTM) - 12.0.2000.8
Operating system: docker container FROM mcr.microsoft.com/dotnet/aspnet:6.0 (debian)