Connection Timeout Expired When there are many requests simultaneously - asp.net

I have a .Net Application(REST API) which accesses SQL Server Database. Sometimes When there are many API requests at the same time, I get Connection Timeout exception due to which all the request fails. This is not always the case and happens only when there are many requests hitting the server at the same time.
Exception Details:
System.Data.SqlClient.SqlException (0x80131904): 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. The duration spent while attempting to connect to this server
was - [Pre-Login] initialization=4; handshake=14992; --->
System.ComponentModel.Win32Exception (0x80004005): The wait operation
timed out.
Any help here will be highly appreciated.

From this (upvoted) comment
in this case may be few reasons:
1. You are using SQL Server Express
2. Dead lock between your queries
3. Queries executed more then standard timeout- 30 sec
You should first exclude N1, as the server Edition has nothing to do with connection timeout that is imposted by client
Then exclude N2 as the deadlocks are resolved automatically by server deadlock monitor that controls for deadlocks every 5 seconds or even less when the deadlocks are frequent.
Than exclude N3 as connection timeout has nothing to do with execution timeout. And your timeout is CONNECTION timeout.
You should increase connection timeout on your client or troubleshoot your server, what happens there that your server becomes unresponsive.

Related

Signalr Unexpected Connection Inactivity Timeout

These are the configuration items the signalr server has
GlobalHost.Configuration.DisconnectTimeout = new TimeSpan(0, 0, 60);
GlobalHost.Configuration.KeepAlive = new TimeSpan(0, 0, 5);
There has never been any inactivity in production for more than 3 years with this setup. It is a self hosted signalr server running as a windows service, and there are evidences that both the client application's and the server's processes are running after the timeout exception that is received in the client. ie No crashes. The client is another windows service running on the same machine as the server. The exception is
System.TimeoutException: The client has been inactive since 26/03/2018 07:00:12 and it has exceeded the inactivity timeout of 00:01:10. Stopping the connection.
Given the above are all that needed to conclude that the keep-alive messages should be sent every 5 seconds by the client, This is totally unexpected, Is this a known bug . as per the docs, the keep alive timeout is not more than 1/3 of the disconnection timeout. The other puzzling information from the error message is that the inactivity timeout is 00:01:10 which does not match up with anything (neither of default or the configured timeouts).
Am I missing something obvious ?

Unable to enable receive locations (many of them)

Whenever I try to enable these receive locations, I get the sql time out error. Moreover there are many service instances and messages which are in active state or Dehydrated (Queued awaiting processing).
TITLE: BizTalk Server Administration
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. (.Net SqlClient Data Provider)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=-2&LinkId=20476
ADDITIONAL INFORMATION:
The wait operation timed out
BUTTONS:
OK
I had tried restarting the host instances, but it did not work. The environment is a clustered server. There looks like no performance issue: no memory or cpu spikes.

ODP.NET Connection Pooling Issues - Fault Tollerance After Database Goes Down

I have an WebAPI service using ODP.NET to make connections to several oracle databases. Normally the web service would be hit several times a second and will never have long periods on inactivity. In our test site however, we did not use it for 2-3 days. This morning, we hit the service and got "connection request timeout" exceptions from ODP.NET, suggesting that the connection pool was out of available connections. We are closing the connections after use. The service was working fine before the period, but today the very first query got the timeout exception. Our app pool in IIS is configured to never reset.
My question then is, what can cause the connection pool to fill with bad connections after a period of inactivity, where these connections are not cleaned up in the usual 3 minute cycle? It only happened to 2 out of the 3 of our databases, and Validate Connection=true is set for all of them.
EDIT
So after talking to the DBA, there is some different between a connection/session being killed manually or by timeout and the database server severing the TCP connections. In this case, the TCP connection was severed as part of a regular backup (why is not important for this). I guess this happens when the whole database server goes offline at once. The basis of the question still applies I think though: why is ODP.NET unable to cleanup severed connections overtime? There is a performance counter that refers to "Stasis" connections, could those connections be stuck in that state? I would think that it should be able to see that a connection is no longer active (Validate Connection=True), kill it and not return it to the pool.
Granted, this problem can be solved by just resetting the app pool everything the database goes down. I would still like to configure ODP.NET connection pooling to be more fault tolerant.
I have run into this same issue, and the only solution I have found is to use the Connection Lifetime connection string parameter in conjunction with Validate Connection.
In my particular case, the connection timeout was set at the server and the connections in the pool would timeout, but not be sniped out of the pool, resulting in errors.
Setting both the Connection Lifetime and the Validate Connection parameters has resolved the issue.
Make sure the Connection Lifetime value that you choose is less than the server connection inactivity timeout.
The recommended solution is to use ODP.NET Fast Connection Failover (FCF). FCF will automatically remove invalid connections from the pool such that you don't need to use Validate Connection, Connection Lifetime, nor clear the pool.
To use FCF, set "HA events=true", use connection pooling, and have your DBA set up Fast Application Notification (FAN) on the server side. FAN is what alerts the ODP.NET pool when a DB service or node goes down or rebooted. Upon receiving the message, ODP.NET knows which connections to remove from the pool and removes them, leaving all other valid connections untouched.
Something else is going on here. Min Pool Size and some of the other settings help when the connection is severed from things like DBA configured idle timeouts and firewall tcp idle timeouts, 'connection request timeout' occurs when created a new connection.
This could be simple network problem. There could be something interfering with dns resolution of the servers. Another case is not having fully qualified entries in tnsnames. I've been bit by the latter a couple of times.
The other issue is the one you've already recognized - full pool.
Double check that you don't have a connection leak somewhere. A missing .Close is one thing but if you're not using a 'using' statement, a try/finally is required as an unhandled exception could be thrown prior to the .Close.
I would use perfmon to monitor some of the connection statistics to start - NumberOfPooledConnections, NumberOfActiveConnections, etc:

How to force close inactive Oracle sessions with ODP.NET

asp.net 2.0 using odp.net 10.1.04 to connect to Oracle 10g.
Our web application has once a day this problem: ODP-1000 "Connection request timed out".
As we know, this is a memory leak problem, caused due open connections that don't get closed and disposed.
We have double checked our code and all connections after open are closed and disposed. All odp.net objects like OracleCommand, Oracledatareader are disposed after used.
On web.config, this is our connection string:
<add key="ConnectionString" value="user id=xxxx;data source=XXXX;password=xxxxx;Pooling=True;Connection Timeout=15;Incr Pool Size=5;Decr Pool Size=3;Max Pool Size=300;Min Pool Size=10;Validate Connection=true;"/>
We have increased Connection Timeout to 60.
As we can't find in our code any unclosed connection, is there any way to close or destroy inactive Oracle sessions when conn.Open gets error "Connection request timed out"?
According to some information:
http://rainmanalex.wordpress.com/2008/11/13/odpnet-connection-string-attributes/
"The regulator thread is spawned every 3 minutes and closes up to Decr Pool Size amount of pooled connections if they are not used. "
Instead of waiting 3 minutes, is there any way to force close an inactive connection when getting error "Connection request timed out"?
Something like:
If conn.Open gets error "Connection request timed out"
Then
Destroy inactive Oracle session
Try again conn.Open
End If

The error threshold has been exceeded. The receive location is shutting down

I am doing polling using SQL adapter......For small records polling is succesful......but for large recorde i am getting following error..
The receive location "RcvSqlDataLoc" with URL "" is shutting down. Details:"The error threshold has been exceeded. The receive location is shutting down.".
Try checking your SQL server management console for deadlocks while the long running transaction is executing. If you don't need a transaction there's an option in the configuration of the port for automatically wrapping the session in a transaction. You might try turning that off.

Resources