SQL timeout for no reason - sql-server

I host an azure appservice and sometimes it gets random timeouts on queries that usually take 1ms to complete. The SQL server is hosted in azure too and they talk to each other in a private network. What could be going wrong. It even happens when there is no load and I do one call. 99% of the calls work but it's the 1% that happens way to frequently. It's causing 40 second timeouts for no reason.
There are almost zero open connections. The database is 1200 DTU. The appservice is p3v2 and has always on. Performance to the database seem to be really good except if a query randomly takes really long. It almost seems like there is a connection issue in the azure backbone. It seems to happen almost once every 40 database requests. The transient error rate is higher than I have ever seen on any application. We never hit above 20% DTU but the errors still happen around 1% DTU. It randomly started happening two weeks ago after maintenance from Microsoft. We did not deploy new code during that time.
The exception I see is:
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: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

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: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
From Microsoft Doc,
Cause:
The SQL Server client is unable to reach the server. The server's firewall may have rejected the connection or the server may not be set up to accept remote connections, which might both lead to this error.
Workaround:
Ensure that the firewall on the machine is set up to let this instance of SQL Server to receive connections and to enable remote connections for SQL Server, use the SQL Server Configuration Manager tool.

Related

ADF Copy Actitity issue

I have an issue where I can preview data from a source, a SQL Server connected through a Self-Hosted IR, but I cannot copy the data to a sink (Azure SQL DB on an EP).
The user account at the SQL Server level has access to the relevant tables, as can be verified by the fact that I can preview data. The sink side dataset also works, as I can use with similar data sources to the source.
If I, for example, try to fetch two specific rows, I can see them in the preview, but it takes 5 minutes for ADF to give an error message which is wildly misleading:
ErrorCode=SqlFailedToConnect,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=Cannot connect to SQL Database: 'ServerName.database.windows.net', Database: 'DatabaseName', User: 'AdminUserName'. Check the linked service configuration is correct, and make sure the SQL Database firewall allows the integration runtime to access.,Source=Microsoft.DataTransfer.ClientLibrary,''Type=System.Data.SqlClient.SqlException,Message=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: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.),Source=.Net SqlClient Data Provider,SqlErrorNumber=10060,Class=20,ErrorCode=-2146232060,State=0,Errors=[{Class=20,Number=10060,State=0,Message=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: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.),},],''Type=System.ComponentModel.Win32Exception,Message=A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond,Source=,'
What am I doing wrong? Is there some setting I am missing?
Please check whether the Azure SQL DB(sink) is accessible from the server on which you have installed the self hosted IR.
YOu would need to whitelist the IP of the Self IR server in Azure SQL DB firewall rules and make some port opening in the IR server for Auzre SQL DB to be accessible.
Basically in case if an IR is being used in a copy activity, both the source and sink must be accessible from the server on which IR is set up

Azure Hybrid Connection SQL Connection stops working. Restart of Web App helps. Problem with EnableRetryOnFailure?

I have an Azure Time stamping Web App connecting to about 50 different customers On Premise SQL databases using Hybrid connection. The web app is an Asp.Net Core 2.2 based C# app using EF.
The app has been working extremely well over 2 years without any errors, but the recent week the SQL connections has during two different times stopped working. They will start immediately after a restart of the web app. This is of course extremely bad for my customers who need 24/7 working.
The Azure failure messages indicate a problem with opening a SQL connection, which comes over time and is resetted by a web restart.
When studying the SQL failures in Azure all gives the same error number 10013 in trying to open the connection:
System.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: 0 - An attempt was made to access a socket in a way forbidden by its access permissions. Error Number:10013,State:0,Class:20
When more carefully examining the failures, it turns out that the first failure starts with a lot of 64-number errors as below (5-8) after which the succeeding errors are of type 10013 for all connections.
System.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake.
(provider: TCP Provider, error: 0 - The specified network name is no longer available.
Error Number:64,State:0,Class:20
My thoughts are: could this be because of using EnableRetryOnFailure as an sqlOption, and for some reason this will congest all SqlOpen tries in case of a badly working single connection.
Code used in the web app:
DbContextOptions dbConnOptions = SqlServerDbContextOptionsExtensions
.UseSqlServer(new DbContextOptionsBuilder(), dbConnectionString,
sqlServerOptionsAction: sqlOptions =>
{
sqlOptions.EnableRetryOnFailure(
maxRetryCount: 10,
maxRetryDelay: TimeSpan.FromSeconds(30),
errorNumbersToAdd: null);
}).Options;
Could this be the reason to my SQL connection problems and would it be better to just let remove the
EnableRetryOnFailure code?
Or could there be a completely other solution to the problem?
Bengt Bredenberg,
Premisol Oy, Helsinki, Finland

SQL Server Alias stopped working

I have configured a SQL Server 2016 alias following this post and it was working, but suddenly it stopped working.
Error message:
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: 0 - The wait operation timed out.) (.Net SqlClient Data Provider)
I created the alias using the SQL Server Configuration Manager and created it in the 32 and 64bit:
When I go to the Protocols for SQL Server Express, all of them are enabled, thus TCP/IP is enabled. Also, the SQL Server Browser service is running.
Looking at the system log there is no relevant message about it, so I'm a bit lost about what could be causing it to stop working. My OS is Windows 10 Pro.
Would you have any clues to help me solve it? Thanks for any help
Check that the SQLEXPRESS instance's port number hasn't changed, which is likely after a reboot or service restart.
Regarding the use of instance aliases, this is pretty much useless if you're also using dynamic ports for this very reason. To me it's more cumbersome to maintain this configuration than it is to maintain a connection string in your program IMHO.

SQL Server not connecting to specific network

I can connect without any problem to my Sql Server (network service) at home or anywhere else except at work. Sometimes it gets a spirit of the moment connection and then just disconnects again.
It keeps giving me this error:
==========================================================================
Cannot connect to winsqls02.cpt.wa.co.za.
==========================================================================
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) (.Net SqlClient Data Provider)
--------------------------------------------------------------------------
I have tried restarting my laptop, pinging the server, changing to another router at work, but nothing seems to work.
Is there maybe a simple reason for this issue, because I can't seem to find any answers on the internet.

A connection was successfully established with the server, but then an error occurred during the pre-login handshake / Login process

I develop an SMS Server that receive SMS, Analysis them and reply to messages. This application developed with entity framework 4.0 and SQLServer 2008.
When I receive SMS I run new thread for that message and analysis and response to message. Each thread has its own new instance of object context and all threads call same stored procedure in SQL Server.
But when large number of SMS arrived to server and number of thread increase, I get one of these 2 error each time:
The underlying provider failed on
Open. A connection was successfully
established with the server, but then
an error occurred during the pre-login
handshake. (Provider: TCP Provider,
error: 0 - The specified network name
is no longer available.)
OR
The underlying provider failed on
Open. A connection was successfully
established with the server, but then
an error occurred during the login
process. (Provider: TCP Provider,
error: 0 - The specified network name
is no longer available.)
I increase Max Pool Size and Connect Timeout to 400 and 150.
Can anyone help me??
Thanx
You might try increasing the timeout setting in SQL Server. The default is 10 minutes.
http://msdn.microsoft.com/en-us/library/ms189040(v=sql.105).aspx
Might be because some connections still get available. Try to do this :
sp_configure 'user connections', 0
go
reconfigure with override
Also check your server properties, in Connections section, that your parameter : Maximum number of concurrent connections is set to 0 (unlimited).
In my opinion, 98% sure, because I recently had the same experience, it is a network issue from the server provider.
for instance: if you are rent the server from Ionos, by default all remote connections are blocked, even though you disable the firewall in the server. you still won't be able to connect remotely. You can, however, do your work on the server without any problem.
To connect remotely, you have to contact the Server provider. They will explain how to enable firewall ports from your control panel.
I contacted my server provider as I almost get frustrated.
here was their response.
click to see the snapshot of their response
And, whola!! every permitted client can connect remotely to the server.
I wish you success.

Resources