Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure SqlException: Database on server is not currently available

Our site has been running for a few weeks in Azure without getting this error:

SqlException: Database 'database' on server 'server' is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of 'guid'.

It finally got that one day when there were a little over 2K of active (concurrent) users. This is the closest question that I can find in SO. We are not using EF though but rather we're using Dapper. I'm out of ideas how to debug our application to find out what caused the issue, and it's even harder now that the issue has not come up for the past 2 days. I definitely need to be on the lookout and I need you guys, any tip, on where I should be looking into, what I need to do to determine the cause of the issue, and possibly fix it.

like image 636
von v. Avatar asked Apr 21 '14 08:04

von v.


People also ask

Can not connect to the database in its current state Azure?

This usually indicates you may have hit a pricing/budget limit on your subscription/resource. Please reach out to your billing administrator to check if any budget restrictions were applied to this resource. If it is still not resolved, please reach out to Azure Support and submit this as a "Billing Issue".

Can't connect to Azure SQL managed instance?

If you are unable to connect to SQL Managed Instance from an Azure virtual machine within the same virtual network but a different subnet, check if you have a Network Security Group set on VM subnet that might be blocking access.

Can't connect to Azure SQL Database from SSMS?

SSMS cannot connect to azure sql databaseYour client IP address does not have access to the server azure. Sign in to an Azure account and create a new firewall rule to enable access. This is for obvious security reasons. You don't want to allow everyone to be able to connect to your sql database in azure.

How do I enable SQL Profiler in Azure SQL Server?

To start Profiler, first make a connection to a server in the Servers tab. After you make a connection, type Alt + P to launch Profiler. To start Profiler, type Alt + S. You can now start seeing Extended Events.


2 Answers

It sounds like you need to handle transient failures via some sort of transient fault handling mechanism. Here is post asking a similar question: SQL Azure Database retry logic David's answer is similar to the approach we took do deal with the issue.

Here is another link to some code that is similar to the David's and our solution to get your head around it. http://www.getcodesamples.com/src/4A7E4E66/41D6FAD

We had similar issues when we first moved to SQL Azure but by implementing back-off retry logic for the transient connection issues the majority of the time it recovers after a few seconds.

like image 200
ElvisLives Avatar answered Oct 04 '22 23:10

ElvisLives


We went down the path of handling transient errors with the Azure Transient Fault Block, but this caused bigger issues - namely, if you reach the SQL connection limit (easy to do), having retry logic in place only makes things worse.

If it only happens once a month, I'd leave it be, and just handle it gracefully higher up the stack. An alternative is to create a custom retry policy to avoid retrying on certain errors, but it may still do more harm than good.

like image 27
Dunc Avatar answered Oct 04 '22 23:10

Dunc