Pooling and SqlConnetion?

  • Thread starter Thread starter perspolis
  • Start date Start date
P

perspolis

Hi all
I use 'Pooling=true;' in my connection string;
how can I disable 'pooling' in my application and close all connections???
thanks in advance
 
perspolis,

I wouldn't necessarily do that. What is the purpose here? Just killing
a database connection is a bad thing, since you could be closing it in the
middle of an important operation.

You can always just not place "pooling=true" in the connection string,
and the connections will not be pooled, they will close when your code
closes them.

Of course, you should always use the using statement to make sure your
connections close when you are done using them.

Hope this helps.
 
Pooling=true is the default, it will be on even if this element is not
present in the connection string. change it to:

Pooling=false;

Now as long as you Close each connection, no connections will be returned to
the pool. I think its important to understand that pooled connection objects
are just connection objects, they are not left "Open" - until you open them.

Why do you want to disable connection pooling?

Peter
 
Nicholas said:
I wouldn't necessarily do that. What is the purpose here? Just killing
a database connection is a bad thing, since you could be closing it in the
middle of an important operation.

You can always just not place "pooling=true" in the connection string,
and the connections will not be pooled, they will close when your code
closes them.

Of course, you should always use the using statement to make sure your
connections close when you are done using them.

That doesn't make sure the physical connections will be closed though.

Before now I've had cause to want to remove connections from the pool
having killed them on the SQL Server side (if you're not careful, the
pool doesn't notice that they've died, and you get an exception next
time you try to use them).

Fortunately, in .NET 2.0 you can use SqlConnection.ClearAllPools (or
ClearPool for a specific pool) to do this. Unfortunately I wasn't
working with 2.0 at the time :(

Jon
 
Jon said:
That doesn't make sure the physical connections will be closed though.

Just to anticipate a reply - yes, it will kill the physical connections
if you have pooling turned off to start with. I hadn't noticed that bit
of Nick's reply :)

Jon
 
Back
Top