Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"The connection is closed" errors in System.Data.SqlClient - Async operations #1524

Closed
radekfojtik opened this issue Feb 23, 2022 · 2 comments

Comments

@radekfojtik
Copy link

radekfojtik commented Feb 23, 2022

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."

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)

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)

@JRahnama
Copy link
Contributor

@radekfojtik The issue #796 is addressed in Microsoft.Data.SqlClient and not System.Data.SqlClient. Is it possible for you to test with Microsoft.Data.SqlClient .

Just to mention that System.Data.SqlClient is in servicing mode and not receiving updates , but for security issues. Whereas, M.D.SqlClient is ADO.NET's active library and receives updates on regular basis.

@radekfojtik
Copy link
Author

radekfojtik commented Feb 23, 2022

@JRahnama Thank you, I didn't notice that the fix is only for Microsoft.Data.SqlClient .. So I'm closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants