Azure SQL Database Sometimes Unavailable on Azure Sites

I have an asp.net application deployed on Azure sites connecting to Azure SQL Database. This works great last year, but last weekend I started getting errors related to the database providing the next stack.

[Win32Exception (0x80004005): Access is denied]

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]

This error comes and remains for several hours, and then leaves for several hours. The database is always accessible from my machine.

A few things I tried:

  • Adding the "allow all" firewall rule (0.0.0.0-255.255.255.255) has no effect
  • Changing the connection string to use the database owner as the credential is not affected.
  • What can affect the change in the level of hosting azure on something else. This temporarily resolves the issue, and the website can access the database for a few more hours.

What could happen to make this error appear? The application has not been changed since August.

EDIT: Azure Support detected that the instance had a socket and port. What is the main reason for this, has not yet been disclosed.

+2
source share
2 answers

A response from Azure support showed that the connectivity issues I was experiencing were related to port / socket depletion. This was probably due to another site in the same hosting plan.

, :

  • , .
  • B S , B.
+1

, SQLAzure. : https://msdn.microsoft.com/en-us/library/hh680899(v=pandp.50).aspx

PolicyRetry , SQL Azure ExecuteAction, . SQL Azure ReliableSqlConnection .

, SQL Azure.

using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling;
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.AzureStorage;
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.SqlAzure;

...

// Get an instance of the RetryManager class.
var retryManager = EnterpriseLibraryContainer.Current.GetInstance<RetryManager>();

// Create a retry policy that uses a default retry strategy from the 
// configuration.
var retryPolicy = retryManager.GetDefaultSqlConnectionRetryPolicy();


using (ReliableSqlConnection conn = 
  new ReliableSqlConnection(connString, retryPolicy))
{
    // Attempt to open a connection using the retry policy specified
    // when the constructor is invoked.    
    conn.Open();
    // ... execute SQL queries against this connection ...
}

SQL .

using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling;
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.AzureStorage;
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.SqlAzure;
using System.Data;

...

using (ReliableSqlConnection conn = new ReliableSqlConnection(connString, retryPolicy))
{
    conn.Open();

    IDbCommand selectCommand = conn.CreateCommand();
    selectCommand.CommandText = 
      "UPDATE Application SET [DateUpdated] = getdate()";

    // Execute the above query using a retry-aware ExecuteCommand method which 
    // will automatically retry if the query has failed (or connection was 
    // dropped).
    int recordsAffected = conn.ExecuteCommand(selectCommand, retryPolicy);

}
+2

Source: https://habr.com/ru/post/1665891/


All Articles