"Database on server is not currently available. Please retry the connection later."
There are two types of Azure SQL Database connectivity issues: transient errors and persistent errors. According to your error message, it seems to belong to transient errors. Database reconfiguration and database resource limits all could cause this error. In this article, we could know some steps to resolve transient connectivity issues.
Besides, you could check your connection string, firewall settings, connection code or any other possible causes.
Connection string in app.config file:
<connectionStrings>
<!-- The format of the connection string is "DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY" -->
<!-- For local execution, the value can be set either in this config file or through environment variables -->
<add name="AzureWebJobsDashboard" connectionString=" storage connection string" />
<add name="AzureWebJobsStorage" connectionString=" storage connection string" />
<add name="ConnectionStringName" providerName="System.Data.SqlClient" connectionString="Data Source=tcp:[your azure sql server name],1433;Initial Catalog=[sql database name];Integrated Security=False;User Id=[user name];Password=[password];Encrypt=True;TrustServerCertificate=False;MultipleActiveResultSets=True" />
</connectionStrings>
Code in Context:
class MyContext: DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString);
}
public DbSet<Student> Students { get; set; }
}
Code in Program:
MyContext context = new MyContext();
var count = context.Students.ToList().Count();
Console.WriteLine("rows number:" + count);
The firewall in Azure Sql Database:
