Re: SqlDataReader.Close() bug?

From: William \(Bill\) Vaughn (billvaRemoveThis_at_nwlink.com)
Date: 07/30/04


Date: Fri, 30 Jul 2004 10:59:16 -0700

This makes sense. You did not cancel the operation. First, you asked for
100,000 gallons of water to be pumped into a tank. You opened the spigot and
took out a couple of gallons and then said forget it.

The server does not know you don't want the rest of the rows. You need to
use Command.Cancel first, then close the DataReader. I expect the server is
still fetching rows and ADO.NET is flushing them.

hth

-- 
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Chris Gallucci" <chris@gallucci.com> wrote in message
news:OMtbmvjdEHA.596@TK2MSFTNGP11.phx.gbl...
> OK, my simple sample is returning an error...
>
> <error>
> System.Data.SqlClient.SqlException: Timeout expired.  The timeout period
> elapsed prior to completion of the operation or the server is not
> responding.
>    at System.Data.SqlClient.SqlDataReader.InternalClose(Boolean
closeReader)
>    at System.Data.SqlClient.SqlDataReader.Close()
>    at SqlDataReaderSample.Class1.Main(String[] args) in c:\my
> documents\visual studio
> projects\sqldatareadersample\sqldatareadersample\class1.cs:line 40
> </error>
>
> This error occurrs after selecting 275,000 records then exiting after
> reading the first 10...
>
> <codesnippet>
> [STAThread]
> static void Main(string[] args)
> {
>     Console.WriteLine("Starting...");
>     string sql = "SELECT MyColumn FROM MyTable WHERE MyID <= 275000";
>     SqlDataReader rdr = SqlHelper.ExecuteReader(CONN_STRING,
> CommandType.Text, sql);
>     try
>     {
>         int i = 0;
>         while ( rdr.Read() )
>         {
>             if ( i++ > 10 ) break;
>             Console.WriteLine(rdr.GetString(rdr.GetOrdinal("MyColumn")));
>         }
>         if ( rdr != null && !rdr.IsClosed )
>         {
>             rdr.Close();
>         }
>         rdr = null;
>     }
>     catch ( Exception ex )
>     {
>         Console.WriteLine(ex.ToString());
>     }
>     finally
>     {
>         if ( rdr != null && !rdr.IsClosed )
>         {
>             rdr.Close();
>         }
>     }
>     Console.WriteLine("Finished. Press any key to exit.");
>     Console.Read();
> }
> }
> </codesnippet>
>
> ChrisG
>
>


Relevant Pages

  • Re: SqlDataReader.Close() bug?
    ... Cancelcan help in some scenarios. ... >> took out a couple of gallons and then said forget it. ... >> The server does not know you don't want the rest of the rows. ... > bool res = rdr.Read; ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: SqlDataReader.Close() bug?
    ... > took out a couple of gallons and then said forget it. ... > The server does not know you don't want the rest of the rows. ... > still fetching rows and ADO.NET is flushing them. ... bool res = rdr.Read; ...
    (microsoft.public.dotnet.framework.adonet)