I've seen this happen when you don't retrieve all the data returned by a
query.  If you abandon the query half way through, SQL Server goes ahead
and processes it anyway, and you have to wait until it's done when you
try to close the connection.

If the query you're performing takes about 10 seconds to run to the end,
that'd be it.

In one particularly egregious case, I came across an app that did
something pretty much like this:

cmd.CommandText = "SELECT * FROM ReallyBigTable";
using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.KeyInfo))
{
    DataTable schema = rdr.GetSchemaTable();

    ...do stuff with schema, but never bother reading
       any data
}

This wouldn't have been so bad if they had passed the
CommandBehavior.SchemaOnly flag instead of accidentally passing the flag
that comes directly before it in the IntelliSense list...  (And it
didn't help that they were doing this for 50 different tables...)

I think the reason they didn't notice the problem is that it all appears
to be working just fine if you step through it.  It's just that when you
close the connection, at that point it waits until SQL Server has
finished processing the query.


-- 
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/

-----Original Message-----
From: Daniel Michaeloff

Hi all,

Why would SqlDataReader.Close() be taking up to 10 seconds?  I'm calling
from a background thread, but that shouldn't make a difference, right?

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to