You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider handling error code 40613 with stretched timeout with default retry logic provider #1957
When connecting to a serverless database, it's reasonable to receive error code 40613 as the database resumes. But resuming can take as long as ~45 seconds, in which case driver generally times out even with the default Retry logic provider.
Exception message: SqlError.ctor | ERR | Info Number 40613, Error State 1, Error Class 20,
Error Message 'Database '<>' on server '<>.database.windows.net' is not currently available.
Please retry the connection later.
To reproduce
Connect to a serverless database when it's paused.
Proposal
Since the driver receives the error code with the default retry logic provider, the driver could provide a log (Waiting for database to resume) and retry connection after some time (additional 30 seconds delay) - so it can resume and successfully connect in the next connection attempt.
Most users would like to not have to worry about this use case, even if it takes a bit longer to wait for database to resume.
Thanks @cheenamalhotra for identifying this issue and making a suggestion to provide a better user experience. We'll discuss it with the team regarding this enhancement.
How would we differentiate 40613 between a database that is paused and one that truly doesn't exist? (They are still the same error, right?) I wouldn't want to implement an extra long pause for scenarios where the database doesn't exist...
For a paused database (not resuming), we get below error:
(tested with paused SQL instance of Azure Synapse dedicated pool)
Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot connect to database when it is paused.
at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
...
ClientConnectionId:554ec90f-cf32-40f9-92c2-bae917b1962e
Error Number:40892,State:1,Class:20
Whereas for a non-existing database we get:
Microsoft.Data.SqlClient.SqlException (0x80131904): Login failed for user '<token-identified principal>'.
at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
...
ClientConnectionId:80148e7d-9e4b-46c0-9ae5-62692e2f7fc8
Error Number:18456,State:1,Class:14
Reading more about it, the other condition 40613 may occur would be when "there is already an existing dedicated administrator connection (DAC) established to the database." explained here.
It would be a valid error in that case, and if increasing timeout, it will fail in timeout +30 seconds (with default retry logic provider). But I think serverless connections are more prominently used than DAC connections, which leads to error been thrown with default timeout.
Reading more about it, the other condition 40613 may occur would be when "there is already an existing dedicated administrator connection (DAC) established to the database." explained here.
Tested again today and noticed that second DAC connection attempt fails with below error now:
Unhandled exception. Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake.
(provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)
---> System.ComponentModel.Win32Exception (10054): An existing connection was forcibly closed by the remote host.
Tested again today and noticed that second DAC connection attempt fails with below error now:
Unhandled exception. Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake.
(provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)
---> System.ComponentModel.Win32Exception (10054): An existing connection was forcibly closed by the remote host.
Just an update, this seems to be resolved now, and doesn't happen anymore - the docs likely need updating. 40613 is now solely for sleeping serverless connection error.
Activity
lcheunglci commentedon Mar 17, 2023
Thanks @cheenamalhotra for identifying this issue and making a suggestion to provide a better user experience. We'll discuss it with the team regarding this enhancement.
David-Engel commentedon Mar 21, 2023
How would we differentiate 40613 between a database that is paused and one that truly doesn't exist? (They are still the same error, right?) I wouldn't want to implement an extra long pause for scenarios where the database doesn't exist...
cheenamalhotra commentedon Mar 21, 2023
For a paused database (not resuming), we get below error:
(tested with paused SQL instance of Azure Synapse dedicated pool)
Whereas for a non-existing database we get:
cheenamalhotra commentedon Mar 21, 2023
Reading more about it, the other condition 40613 may occur would be when "there is already an existing dedicated administrator connection (DAC) established to the database." explained here.
It would be a valid error in that case, and if increasing timeout, it will fail in timeout +30 seconds (with default retry logic provider). But I think serverless connections are more prominently used than DAC connections, which leads to error been thrown with default timeout.
cheenamalhotra commentedon Jul 27, 2023
Tested again today and noticed that second DAC connection attempt fails with below error now:
cheenamalhotra commentedon Nov 22, 2023
Just an update, this seems to be resolved now, and doesn't happen anymore - the docs likely need updating. 40613 is now solely for sleeping serverless connection error.
priyankatiwari08 commentedon Sep 17, 2026
/triage
github-actions commentedon Sep 17, 2026
test simple comment