StrataFrame Forum

Close SQL Connections?

http://forum.strataframe.net/Topic29998.aspx

By Chris Diesel - 5/18/2011

Is there a method I can call to close all the sql server connections.

I'm trying to give the application a way for the user to disconnect from the server (close child windows and cisco vpn) and login again later (open vpn) without closing the main app.  All is working except for when I try to login for the second time.  I'm getting a SqlException: 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).  Could this be caused by the sql connection not being close prior to the vpn shutting down?  Is there a way to close connections?

Thanks!
By Trent L. Taylor - 5/23/2011

It depends on how you are managing your connections.  If you are using a BO, then the connection is never kept open longer than it takes to perform a query, update, etc.  When you are dealing with VPN environments, it is not uncommon for there to be a timeout that will close the connection (socket) to the server.  In this case, you may have to play with the VPN.  But here is what I would do to figure out where your issues are:

  1. Create a test application
  2. Manually create an SqlConnection
  3. Manually create a similar SqlCommand that is causing an issue pre or post connection termination
  4. Execute the query and leave the connection open and then repeat and close the connection to see if you can reproduce the problem
Putting this in a small scale test environment will help you isolate the issue and determine which end you need to be working on.
By Chris Diesel - 5/25/2011

Thanks for the help.  What ended up working was the SqlConnection.ClearAllPools() just prior to disconnecting the VPN.
By Trent L. Taylor - 5/25/2011

Perfect.  Glad you  got it going.