Re: SqlDataReader.Close() bug?
From: Pablo Castro [MS] (pablocas_at_online.microsoft.com)
Date: 07/30/04
- Next message: Miha Markic [MVP C#]: "Re: Item Index in dataset"
- Previous message: Gary Shell: "Re: DataTable made from JOINed tables and the DataAdapter wizard"
- In reply to: Miha Markic [MVP C#]: "Re: SqlDataReader.Close() bug?"
- Messages sorted by: [ date ] [ thread ]
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
>
>
- Next message: Miha Markic [MVP C#]: "Re: Item Index in dataset"
- Previous message: Gary Shell: "Re: DataTable made from JOINed tables and the DataAdapter wizard"
- In reply to: Miha Markic [MVP C#]: "Re: SqlDataReader.Close() bug?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|