Azure SQL unavailable to Web App intermittently - azure

I have a webapp running in Azure. It uses a Azure MSSQL database set to Standard S0: 10 DTUs performance. The backend is written in dot net core 3.1. The app works fine when I visit it.
Checking my logs I found a few of these, they happen weeks apart at odd times.
Microsoft.Data.SqlClient.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: TCP Provider, error: 35 - An internal exception was caught)
This error has me wondering if some random user is unable to access the site because the SQL server won't respond.
Any suggestions as to what this might be about?
Or suggestions as to what I should try doing?
Update 1: As a response to comment regarding retry. I actually have implemented retry on the connection (.net core entity framework) using this code.
services.AddDbContext<ApplicationDbContext>(
options =>
{
options.UseSqlServer(connectionString, sqlOptions =>
{
sqlOptions.EnableRetryOnFailure(
maxRetryCount: 10,
maxRetryDelay: TimeSpan.FromSeconds(10),
errorNumbersToAdd: null
);
});
options.EnableSensitiveDataLogging(true);
},
ServiceLifetime.Transient
);

Related

"Failed to connect to: we.frontend.clouddatahub.net" error while registering Integration Runtime of Azure Data Factory

This is what I followed to setup IR.
In the final step of Registering Azure Data factory self hosted intergration runtime, we need to provide the Authentication Key. then the installation is making a call to internet. Isn't this strange as the VM could be in a private network?
If the VM is not connected to internet and it gets this error then what to do? "Failed to connect to: we.frontend.clouddatahub.net"
This is the error I get
Failed to execute the command ' -Key xxx'. Error message: Microsoft.DataTransfer.DIAgentClient.HostServiceException: Failed to get service token from ADF service with key xxxx and time cost is: 3.0786307 seconds, the error code is: UnexpectedFault, activityId is: xxx and detailed error message is An error occurred while sending the request.
The underlying connection was closed: An unexpected error occurred on a send.
Authentication failed because the remote party has closed the transport stream.
The issue seems to be disabled remote access. How can I enable it? Dmgcmd -era 8060 is not working.
I have also a related issue logged as another VM works and this fails
Even if you have some private network where the communication can go without any restrictions between your data sources and your integration runtime, the integration runtime application needs to be able to communicate with the Azure data factory services as well. Try whitelisting the IPs for your region in the networking settings of your Azure VM or in your firewall - according to this:
https://learn.microsoft.com/sv-se/azure/data-factory/azure-integration-runtime-ip-addresses

Getting transient errors when making calls against Azure SQL Database from Azure Function

We are using .NET Core 2.1 and Entity Framework Core 2.1.1
I have the following setup in Azure West Europe
Azure SQL Database
-- Premium P2 250 DTU
-- Public endpoint, no VNET peering
-- "Allow access to Azure Services" = ON
Azure Functions
-- Consumption Plan
-- Timeout 10 Minutes
Azure Blob storage
-- hot tier
Multiple blobs are uploaded to Azure Blob storage, Azure Functions (up to 5 concurrently) are fired via Azure Event Grid. Azure Functions check structure of the blobs against metadata stored in Azure SQL DB. Each blob contains up to 500K records and 5 columns of payload data. For each record Azure Functions makes a call against Azure SQL DB, so no caching.
I am getting often, when multiple blobs are processed in parallel (up to 5 asynchronous Azure Functions call at the same time), and when the blob size is larger 200K-500K records, the following transient and connection errors from .NET Core Entity Framework:
1.
An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure()' to the 'UseSqlServer' call.
2.
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 - The wait operation timed out.)
3.
Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. This failure occurred while attempting to connect to the routing destination. The duration spent while attempting to connect to the original server was - [Pre-Login] initialization=13633; handshake=535; [Login] initialization=1; authentication=0; [Post-Login] complete=156; The duration spent while attempting to connect to this server was - [Pre-Login] initialization=5679; handshake=2044;
4.
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 - The wait operation timed out.)
Server provided routing information, but timeout already expired.
At the same time there are any/no health events reported for the Azure SQL Database during the test, and the metrics look awesome: MAX Workers < 3.5%, Sum Successful Connections < 35, MAX Sessions Percentage < 0.045%, Max Log UI percentage < 0.024%, Sum Failed Connections = 0, MAX DTU < 10%, Max Data IO < 0.055%, MAX CPU < 10%.
Running connection stats on Azure SQL DB (sys.database_connection_stats_ex): No failed, aborted or throttled connections.
select *
from sys.database_connection_stats_ex
where start_time >= CAST(FLOOR(CAST(getdate() AS float)) AS DATETIME)
order by start_time desc
Has anyone faced similar issues in combintation with .Net Core Entity Framework and Azure SQL Database. Why I am getting those transient errors, why Azure SQL Database metrics look so good not reflecting at all that there are issues?
Thanks a lot in advance for any help.
using Microsoft.EntityFrameworkCore;
namespace MyProject.Domain.Data
{
public sealed class ApplicationDbContextFactory : IApplicationDbContextFactory
{
private readonly IConfigurationDbConfiguration _configuration;
private readonly IDateTimeService _dateTimeService;
public ApplicationDbContextFactory(IConfigurationDbConfiguration configuration, IDateTimeService dateTimeService)
{
_configuration = configuration;
_dateTimeService = dateTimeService;
}
public ApplicationDbContext Create()
{
//Not initialized in ctor due to unit testing static functions.
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
.UseSqlServer(_configuration.ConfigurationDbConnectionString).Options;
return new ApplicationDbContext(options, _dateTimeService);
}
}
}
I've found this good documentation around sql database transient errors:
Working with SQL Database connection issues and transient errors
From the documentation:
A transient error has an underlying cause that soon resolves itself. An occasional cause of transient errors is when the Azure system quickly shifts hardware resources to better load-balance various workloads. Most of these reconfiguration events finish in less than 60 seconds. During this reconfiguration time span, you might have connectivity issues to SQL Database. Applications that connect to SQL Database should be built to expect these transient errors. To handle them, implement retry logic in their code instead of surfacing them to users as application errors.
Then it explains in details how to build retry logic for transient errors.
Entity Framework with SQL server implements a retry logic:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlServer("<connection string>", options => options.EnableRetryOnFailure());
}
You can find more information here:
EF Core - Connection Resiliency
Remove and recreate database user and make sure to fill Login Name box just below the User Name. This will fix same issue on older SQL versions too.

Azure - 'There was an error while initializing App Service app for blahblahapp' 'Error connecting to SQL server (SQL error code 40532)'

I'm following a tutorial for setting up easy tables in Azure but I'm getting 'There was an error while initializing App Service app for 'blahblahapp'. 'Error connecting to SQL server (SQL error code 40532)'.
My connection string is:
Data Source=tcp:blahblahapp.database.windows.net,1433;Initial Catalog=blahblahapp_db;User ID=myemail#email.com;Password=blahblahpassword.
I've had a similar problem before while following another tutorial where my sql connection credentials were copied from the connection string given by Azure and pasted into a visualstudio c# program but it came up with errors and would not connect using the username myemail#email.com instead of the username given which was the same myemail#email.com I had to put myemail#email.com#database.azurewebsites.net so I'm thinking this could be the problem.
Or is it????
This problem is happening in the Azure console but how do I edit the connection string given by azure so that it is myemail#email.com#database.azurewebsites.net?

Error 19 - Physical connection error

A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable) - occurs intermittently, using hybrid connector to connect to on-premise database from Azure API
I try connecting to SQL database in on-premise sever from app service resource (Web API). Configured classic hybrid connection end point to on-premise db.
Root Cause :
In SQL database, there is a property 'Auto Close' in Options tab, which is set to TRUE by default.
When Azure Service(API) establishes connection to SQL server. Azure tries to maintain the same connection pool and try to reuse and reconnect to it.
As we have set 'Auto Close as TRUE', the SQL database clears the existing connection after sometime. Whereas Azure tries to reconnect with the earlier connection which has already been cleared by SQL database. This results in 'Physical Connection is not usable - error 19'.
SOLUTION:
In SQL db, go to database properties. Navigate to 'OPTIONS' page and expand automatic tab and set 'AUTO CLOSE' property as 'FALSE'.
Make sure you restart Azure app and your database server to ensure no old connections are used.
PROBLEM SOLVED.
NOTE : This is one of the reason (which happened to me).
Another useful method to get rid of this error is to use RETRY LOGIC of Entity Framework 1.1.0
services.AddDbContext<DbContext>(options => options.UseSqlServer('yourconnectionstring',
sqlServerOptionsAction: sqlOptions =>
{
sqlOptions.EnableRetryOnFailure(
maxRetryCount: 5,
maxRetryDelay: TimeSpan.FromSeconds(30),
errorNumbersToAdd: new List<int>() { 19 });
}));
In Retry logic, error 19 is not included. So you have to pass the error code 19 to set retry logic for error code 19.
It seems you need to add a retry logic to your Web API as explained here. The "Physical connection is not usable" error may be caused by transient errors as explained on this Microsoft documentation.
"Transient fault errors typically manifest as one of the following error messages from your client programs:+
•Database on 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
•Database on 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 . (Microsoft SQL Server, Error: 40613)
•An existing connection was forcibly closed by the remote host.
•System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SqlClient.SqlException: A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable)
•An connection attempt to a secondary database failed because the database is in the process of reconfguration and it is busy applying new pages while in the middle of an active transation on the primary database."

Hosting Parse on Azure - Internal Server Error

EDIT: I have enabled logging, here is the error in more detail:
Uncaught internal server error. { [MongoError: Authentication failed.]
name: 'MongoError',
message: 'Authentication failed.',
ok: 0,
code: 18,
I've been following the Microsoft Azure guide to setting up Parse on Azure, which is here.
I've completed the steps and have everything up and running, however, when I try to create a new account on my Obj-C app, I get the error [Error]: {"code":1,"message":"Internal server error."} (Code: 1, Version: 1.12.0).
I'm not sure why this happens, as I can see on Azure that I am getting multiple requests and HTTP errors.
Also the parse source I'm using is the one Azure have provided/forked, so maybe that's where the error is coming from?
Thanks.
The error is with your MongoDB authentication. Double check you followed the steps correctly for the Parse on Azure tutorial, so that there isn't any hard coded incorrect "username/password123" strings
Double check that the URI is correct. I had some issues when migrating. If you use the Parse Server Managed on Azure, it creates the server for you and you can check the Database URI structure there. (In the web app - application settings - DATABASE_URI)
You can also open the settings of the documentDB and check the URI settings there.
Another trick is that if you change the DATABASE_URI setting (in application settings) make sure you restart your web app.
Make sure you have added "/parse" at the end of your URL

Resources