codingdir logo sitemap sitemap |

tcp connection issue for unreachable server after connection

By : , Category : sockets

This is by design.

If two endpoints have a successful socket (TCP) connection between each other, but aren't sending any data, then the TCP state machines on both endpoints remains in the CONNECTED state.

Imagine if you had a shell connection open in a terminal window on your PC at work to a remote Unix machine across the Internet. You leave work that evening with the terminal window still logged in and at the shell prompt on the remote server.

Overnight, some router in between your PC and the remote computer goes out. Hours later, the router is fixed. You come into work the next day and start typing at the shell prompt. It's like the loss of connectivity never happened. How is this possible? Because neither socket on either endpoint had anything to send during the outage. Given that, there was no way that the TCP state machine was going to detect a connectivity failure - because no traffic was actually occurring. Now if you had tried to type something at the prompt during the outage, then the socket connection would eventually time out within a minute or two, and the terminal session would end.

One workaround is to to enable the SO_KEEPALIVE option on your socket. YMMV with this socket option - as this mode of TCP does not always send keep-alive messages at a rate in which you control.

A more common approach is to just have your socket send data periodically. Some protocols on top of TCP that I've worked with have their own notion of a "ping" message for this very purpose. That is, the client sends a "ping" message over the TCP socket every minute and the server responds back with "pong" or some equivalent. If neither side gets the expected ping/pong message within N minutes, then the connection, regardless of socket error state, is assumed to be dead. This approach of sending periodic messages also helps with NATs that tend to drop TCP connections for very quiet protocols when it doesn't observe traffic over a period of time.

ReLated :

Your connection string says AttachDbFilename=|DataDirectory|myDB.mdf. Well, your path must have changed in one place (SQL Server) and not the other (app configuration). AttachDbFilename will try to create a new DB if it can't find that file. That's probably your error.

As an aside, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, and Windows Server 2012 R2 all have differences, especially with security and in particular with how SQL Server behaves, but you keep using them interchangeably. That makes it very confusing to tell what's going on. Also, your connection string says Data Source=.SQLEXPRESS. Is this SQL Server Express? Because that has important differences with most other editions of SQL Server, too. More recent editions are very similar to Standard edition, but the older the edition, the more quirks it has. They're generally considered different beasts.

We figured out what was causing our issue although I may not be able to explain entirely why it mattered.

In IIS there is a setting in the "HTTP Response Headers" under "Set Common Headers" called "Enable HTTP keep-alive". We check marked this option as true and our Windows Authentication started working again.

It seemed to have something to do with the connection not staying open between requests and the application or IIS not realizing the connection was restarted during the SYNC operation.

According to your code Data Source = .SQLEXPRESS, you'r trying to connect to a local server. If so you don't need any ID and Password. And be aware of using Catalog, it's somehow tricky and I hate it. To know how it's working, check this out.

Actually I'm using this code and it works like a charm:

SqlConnection con = new SqlConnection(@"Server = localhost; Database = furniture_display; Integrated Security=True;");

The system has something else running on it that is eating up all its sockets or FDs. Maybe the RAM size is less so the system might be unable to create more connection..


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © All Rights Reserved .