Disconnecting form the SQL server

J

John J. Hughes II

I have an application that connects to an SQL server. I need to be able to
disconnect all connection that I opened. I am closing and disposing the
connection but the connection pool is keeping them alive for later use. How
do I convince the connection pool to drop the connections without closing my
program.

Regards,
John
 
N

Nicholas Paldino [.NET/C# MVP]

John,

If you are going to use the connection pool, then the pool will decide
when to close the connections it is holding. After all, if your program is
still running, you might need them again, right?

If you want, you can turn off connection pooling by altering the
connection string, placing:

Pooling=False

In the string.

Hope this helps.
 
W

Willy Denoyette [MVP]

John,

From the connection pool, these will only be removed from the pool (and the
connection with the DB server closed) after a certain time-out period
(provider specific).
You can make sure the DB connection is closed whenever you close or Dispose
your Connection object (say SqlConnection) by specifying a "Connection
Lifetime" value other than zero .
Note that when doing this you will loose the advantage of connection
pooling.

Willy.
 
G

Guest

John,
The connections that have been returned to the Connection Pool aren't "open".
When you re-use a connection string, ADO.NET checks the pool to see if it
has a matching one and returns the connection object. You still have to open
this connection to use it, so it wasn't "tying up" SQL Server by sitting in
the pool.
Hope that helps clarify.
Peter
 
J

John J. Hughes II

When my program first starts and for a long while there after I want
connection pooling so it is enable. At some point I need to do maintance to
the DB so I need all connection to the DB dropped or I get and error. So at
that point will not need them later and want them to go away. I will then
need them back again so I would like them to start working.

Basially I need to be able to disconnect the connection pool connection
without closing my program.

Regards,
John

Nicholas Paldino said:
John,

If you are going to use the connection pool, then the pool will decide
when to close the connections it is holding. After all, if your program
is still running, you might need them again, right?

If you want, you can turn off connection pooling by altering the
connection string, placing:

Pooling=False

In the string.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

John J. Hughes II said:
I have an application that connects to an SQL server. I need to be able
to disconnect all connection that I opened. I am closing and disposing
the connection but the connection pool is keeping them alive for later
use. How do I convince the connection pool to drop the connections without
closing my program.

Regards,
John
 
J

John J. Hughes II

Oh, maybe I am misunderstanding something then. If I open enterprise
manager and view the process info it says my application has 4 sleeping
connections which are causing me errors. The only way to remove the 4
connections is to close my application. My best guess was the connection
were being held by the connection pool, I know they are being closed from my
application. Do you know where they are coming from and how to close them?

Regards,
John
 
J

John J. Hughes II

Thanks for the response. Basically that is what I concluded but was seeing
if there was something I missed, guess not.

Thanks,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top