Closed JamiePed closed 1 month ago
@JamiePed can you try by setting ConnectRetryCount = 0
in your connection string?
Hey @JRahnama we can try adding that to the connection string - how would disabling retries help?
We're struggling to replicate this issue so it'll be hard to validate whether or not this helps, it seems to be dependent on the health state of SQL Server and the state of the connection during a given request which we've not managed to force in a test environment yet.
We think this is something to do with connection pooling, and the connection not being forcibly removed from the connection pool when it gets into this state - would this option help with that?
@JamiePed , did you find any workaround or resolution? we've been facing the same issue and we've the same technical details as yours (except we're running our apps as webapps) and the version of Microsoft.Data.SqlClient
is 5.0.1
We think this is something to do with connection pooling, and the connection not being forcibly removed from the connection pool when it gets into this state
Are you able to capture exception and call 'ClearPool' with SqlConnection instance? Make sure you close connection so it goes back into pool, and then call ClearPool.
But it's strange why error doesn't go away.. do try capturing traces, as issues like these are very tricky to catch.
Closing as stale
Describe the bug
We've been experiencing issues while trying to recover from temporary drops in database availability. Different instances of the application (hosted in AppService instances) will continuously throw SqlExceptions until the instance is recycled (I.e. we scale up/down or forcibly drop the misbehaving instance). Restarting the App doesn't help.
The initial exception is thrown, understandably because the database isn't available. But every attempt to connect to the DB once it becomes available fails until we move the application to a different instance.
To reproduce
This is difficult to reproduce, the problem doesn't happen every time on every instance. Sometimes one of the 3 instances of the app will fall over, sometimes all 3. Sometimes other applications are affected, sometimes they won't be.
Scale or Patch the DB while constantly opening connections (for different requests). Exception is thrown while the database is not available Database becomes available Instance will continue to throw this exception until
Expected behavior
We get errors during downtime but the app is able to recover as soon as the DB beocmes available
Further technical details
Microsoft.Data.SqlClient version: 4.1.0 .NET target: net6.0 SQL Server version: Azure SQL Operating system: Linux Docker Container hosted on App Service
Additional context So far all I can guess is that the Connection Pool is storing an invalid connection. The method call
LogConnectionNotification
is only called a handful of times as shown hereBut the Exception, with the stack above is thrown thousands of times,
So we attempt to create the connection, it errors, but ends up in the pool so whenever we create a new one we continue to pick up that same connection.
Any help anyone can give would be super useful thanks!