Search code examples
sql-servervb.nettcpdatabase-connectionspid

Transport-level error: SQL Server lost connection (forcibly closed by remote host) after windows sleep mode


I built a VB .NET app which has a connection to SQL Server. While the app is running, the Windows OS changes to sleep mode. After I turn the machine on again, I found this error:

A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)

The connection's state is still OPEN, but it no longer works. I've read some resources from MSDN said the SPID has been terminated(?).

Is it possible to get this connection working again after Windows OS sleep?

If not, I may decide to END the running app..


Solution

  • SQL Server detected that the client wasn't there on sleep, so closed the session, released locks, rolled back etc.

    Your application thinks "open" because it simply remembers it state.

    You should open connections as you need and close afterwards so you won't end up in this condition. The open/close has little overhead because of connection pooling