My application connects to several SQL Server instances (Using SMO and ADO.net), these connections are all closed properly (I’m using Using), one connection is a SqlDependency for table change notification.
Part of the application establishes an encapsulated VPN connection to a remote system, this causes all network resources to be unavailable, including the SQL instances.
What would be recommended method of handling this scenario? Where a network\sql disconnect is frequent but predictable.
I’m using connection pooling so have no control over re-establishing a connection, if I attempt to open a connection (Which retrieves an available connection from the pool) it will fail as soon as I attempt to use it. (As pooled connections are not tested to save overhead).
Use the
NetworkChangeclass to react to IP address table changes that would indicate that is worth trying again. This class would notify you when the VPN connects and when it disconnects. When the you detect a change, clear all connection pools withSqlConnection.ClearAllPools.You should also investigate alternatives to VPN that still allow you to see local network resources while connected remotely, like DirectAccess.