-
Notifications
You must be signed in to change notification settings - Fork 299
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
SqlConnection.State value is not updated when connection is broken #1874
Comments
Hi @Charles-Gagnon , thanks for bringing this to our attention and thanks for providing the repro sample. We'll take a look after the release. |
This behavior is by design. Connection State does not change outside of client server communication. The only things that change State are the application closing the connection or some kind of failure of an active call between the client and the server. There are no performant opportunities for the driver to change the connection state outside of those events. |
Why is the above example not considered a "failure of an active call"? I try to execute a query and it fails with a connection error. |
The documentation for State specifically says :
which in the above example is false - I tried to execute a network operation but it was broken and so failed. |
Thanks for your response. I'll do some investigation after our release. |
I've talked to @Charles-Gagnon offline on this, and I had few points to add: Error with Class 20 is not retriable, as in this case, so application must not retry (as per guidelines), for now I would recommend that to be handled. For SqlClient, since the error class is 20 and this is infact a login failure, the driver should be able to update the connection state to 'Closed' and make it ready to be re-opened. The parser is also disconnected here so it doesn't change the fact that this connection will never be reusable in this state. It has to be re-opened by applications if this error occurs. Doing so is presumably safe for driver since closing an already closed connection doesn't lead to exception (for applications capturing this error with class 20 and closing connection). |
Closing the issue. PR #1953 is merged with the fix for this issue. |
Describe the bug
Note, this may be happening in other scenarios as well. But this is a clear example of behavior I wasn't expected so figured we'd start from there.
The root issue is that the State property doesn't match what I'd expect when the connection to the server is broken.
To reproduce
Expected behavior
I expect an exception to be thrown (this happens) and the connection state to be Closed/Broken (this does not happen).
Instead I get the failures but the connection State stays as open
Further technical details
Microsoft.Data.SqlClient version: 5.1.0-preview2.22314.2
.NET target: .NET 6.0
SQL Server version: SQL 2022
Operating system: Docker container
The text was updated successfully, but these errors were encountered: