Slow app closing when SqlConnection used with Pooling=true

M

Moe Sisko

Using dotnet 2.0.

Console app to reproduce issue :
==
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace DBSlow
{
class Program
{
static void Main(string[] args)
{
using (SqlConnection conn = new SqlConnection("Integrated
Security=true;database=YourDB;server=.;Pooling=true"))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("select GETDATE()")) // just do
something with SQL server
{
cmd.Connection = conn;
cmd.ExecuteNonQuery();
}
}

Console.WriteLine("done");
}
}
}
==

When this code is run, I'm seeing about a 1 to 2 second delay from the time
that : "done" gets displayed, to the time that the application terminates.
i.e. run it from a command shell, and it should be easy to see.

When I turn connection pooling off (by using "Pooling=false" in connection
string), I don't see this delay.

The delay is a problem for us, because in real life, the real app can get
called many times in a batch file.

Any ideas if this delay is by design for connection pooling ?
Any way to reduce/eliminate it with connection pooling on ?
 
M

Moe Sisko

Moe Sisko said:
When this code is run, I'm seeing about a 1 to 2 second delay from the
time that : "done" gets displayed, to the time that the application
terminates. i.e. run it from a command shell, and it should be easy to
see.

Any ideas if this delay is by design for connection pooling ?
Any way to reduce/eliminate it with connection pooling on ?

It seems adding : SqlConnection.ClearAllPools(); just before the
application closes gets rid of the delay !
(BTW, I'm using dotnet 2.0.50727 SP1).
 

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