Re: SqlDataReader.Close() bug?

From: Pablo Castro [MS] (pablocas_at_online.microsoft.com)
Date: 07/30/04


Date: Fri, 30 Jul 2004 13:39:03 -0700

There is no need to empty the reader before closing it. When you call close,
we'll read all the rows and then close it (yes, you'll have to wait until we
stream the entire result-set to the client; I you don't need that many rows,
it's much better to filter on the query on the server side). Calling
Cancel() can help in some scenarios.

In any case, you should never see the process just dispear because of that.
There are a number of exeptional conditions such as some out-of-memory and
some stack-overflow scenarios where the CLR will "fail fast", meaning that
the process will terminate immediately because the integrity of the address
space cannot be guaranteed. You should see this only in extreme scenarios
(e.g. are you doing some form of very deep recusion?).

If you can come-up with a stand-alone reproduction of the problem that we
can run here at MS, I would be *very* interested on debugging the thing and
seeing what's going on. You can post the repro program here on the
newsgroups or feel free email me directly.

-- 
Pablo Castro
Program Manager - ADO.NET Team
Microsoft Corp.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:eoqOkVmdEHA.3964@TK2MSFTNGP10.phx.gbl...
> Hi Bill,
>
> "William (Bill) Vaughn" <billvaRemoveThis@nwlink.com> wrote in message
> news:eKuZv7ldEHA.3792@TK2MSFTNGP09.phx.gbl...
> > 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.
>
> I am not sure if this is the case because:
> a) it really shouldn't just exit the application
> b) this ugly piece of code works just fine (note that there are more than
> two records)
> sqlConnection1.Open();
>
> SqlCommand cmd = new SqlCommand("SELECT * FROM Orders", sqlConnection1);
>
> SqlDataReader rdr = cmd.ExecuteReader();
>
> bool res = rdr.Read();
>
> res = rdr.Read();
>
> rdr.Close();
>
> sqlConnection1.Close();
>
>
>
> Well, just my feeling.
>
>
> -- 
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> miha at rthand com
> www.rthand.com
>
>


Relevant Pages

  • 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)
  • 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. ... > This error occurrs after selecting 275,000 records then exiting after ... > static void Main(stringargs) ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Exch 5.5 Migration to Exch 2003 (1 domain)
    ... Both Scenarios should be supported. ... So long as your domain is Native Windows, then follow the Deployment tools. ... Run the Deployment tools on the server 2. ... So long as the Exchange 5.5 Server is up and running when the outlook logs ...
    (microsoft.public.exchange.setup)
  • special characters and how they are represented
    ... so, i have this album from Mötley Crüe (that looks right in vim, my ... on the server, however, the directory name doesn't look like ... consistent behavior across all three scenarios? ...
    (freebsd-questions)
  • Re: SLOW LOGON TO WINDOWS 2003
    ... In some scenarios the solution where simply configuring the dns client ... >Server 2000 domain from the same machine loads immediately. ... >Any ideas what would cause such a hang. ...
    (microsoft.public.windows.server.general)