Azure SQL connection failure

Asked

Viewed 77 times

0

I am receiving the error message below when trying to connect to a database hosted in AZURE through a WEB application:

An Exception has been raiset that is likely due to Transient Failure. If you are Connecting to Sql Azure database, consider using Sqlazurestrategy.

I disabled the firewall of the bank to check if this could be the problem, but it did not solve.

I am able to connect through SQL Server Management Studio, but not through the application.

Application connects to bank via EF6

var usuario = Db.Usuario.Where(x => x.Login == login).FirstOrDefault();
            if (usuario != null && usuario.ProfissionalID.HasValue)
            {
                usuario.Profissional = Db.Profissional.Where(x => x.ProfissionalID == usuario.ProfissionalID).FirstOrDefault();
            }
            return usuario;

I saw an article from Microsoft to implement this snippet of code to solve the problem:

public class DbContextConfiguration : DbConfiguration
    {
        public DbContextConfiguration()
        {
            SetExecutionStrategy(
                "System.Data.SqlClient",
                () => new SqlAzureExecutionStrategy(1, TimeSpan.FromSeconds(30)));
        }
    }

I did, but it seems to me that he makes several attempts of connection to each, until one is successful.

But it seems to me that the server is unstable, because I just could not connect, using Sqlazureexecutionstrategy.

I just got another error message:

Maximum number of retries (1) exceeded while executing database Operations with 'Sqlazureexecutionstrategy'.

  • Are you using C#? Post your connection code

  • Are you using SqlAzureStrategy?

  • I think the problem is not the connection but something that you are trying to execute and there is giving the error above. the sql of Azure is very boring even.

  • put the connection string, removing the database name, user and password.

  • <add name="Entities" connectionString="Metadata=res:///Context.ControleHorasContext.csdl|res:///Context.ControleHorasContext.ssdl|res://*/Context.ControleHorasContext.msl;Provider=System.Data.Sqlclient;Provider Connection string=&quot;data source=XXX;initial Catalog=XXX;persist security info=True user id=XXX;password=XXX;Multipleactiveresultsets=True;App=Entityframework&quot;"providerName="System.Data.Entityclient" />

1 answer

0


I don’t think it’s a database problem, otherwise you would see an error very different from the current one, something like saying that the IP address is not allowed access by the firewall.

Instead I would try to look at Markus Wagner’s answer where he says about the parameters of maxRetryCount and maxDelay. I think this should be a good start to ensure that your code is well prepared to work with these classes.

Then there are a number of published best practices on how to work with Azure SQL service. I would seek to make sure that you are attending to all these best practices and try to adjust where possible. I would try:

  • Minimize the network latency
  • Reduce network usage by implementing application cache
  • Manage network connection while keeping it open as little as possible
  • Tunar your queries SQL
  • Implement multiple-try logic.

Translated from the answer in English

Browser other questions tagged

You are not signed in. Login or sign up in order to post.