Re: Closing connections

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Complex bound controls (those that deal with the entire rowset)
automatically close the DataSource when they complete population. This means
you don't have to close a DataReader when binding it to a Grid or List.
However, this assumes that you've set the CommandBehavior.CloseConnection on
the ExecuteReader.

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
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.
__________________________________

"tshad" <tfs@xxxxxxxxxxxxxx> wrote in message
news:uzYCSrrFGHA.2896@xxxxxxxxxxxxxxxxxxxxxxx
>I have been misunderstanding the closing of the connection.
>
> If I have set CommandBehavior.CloseConnection, I thought that connection
> would be closed when you had read through the dataread. As a matter of
> fact
> I found that if I had it set, I couldn't seem to get to the next results,
> if
> there were multiple results (NextResult() would give me an error).
>
> Now I find that I need to close the Reader to close the connection.
>
> This is a problem with my Database object. I have an object
> (RunProcedure)
> that executes a stored procedure and then returns a DataReader. I have
> the
> reader set to CommandBehavior.CloseConnection. This would be ok as I can
> close the DataReader, which should close the connection if I do a:
>
> dbReader = RunProcedure(...)
> dbReader.Close()
>
> But how do I deal with (or can I) the situation where I do a direct
> Databind
> to Grid, listbox, etc?
>
> DataGrid1.DataSource = RunProcedure()
>
> I have no DataReader to close.
>
> Thanks,
>
> Tom
>
>


.



Relevant Pages

  • ADO.NET 2.0 - ResultSet concerns
    ... Unless you use a DataReader or Command.Executexxx methods. ... So the golden rule is Open your connection Only when you need to and close ... And tell me that Disconnected methodology isn't going to be widely abandoned ... by 1) newbies 2) former ADO users 3) people who still don't like dealing ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: ADO.NET 2.0 - ResultSet concerns
    ... features removed but I think a strong ... >- ADO.NET is billed as a 'disconnected' methodology. ... Unless you use a DataReader or Command.Executexxx methods. ... >So the golden rule is Open your connection Only when you need to and close ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Passing a DataReader between methods and getting RETURN_VALUE
    ... because I still have to iterate thorough all the records of the DataReader. ... instead of passing DataReader, which requires open connection. ... Passing datareaders is problematic and passing ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Will this close/dispose properly?
    ... Command is set to null. ... Connection object are reacheable and are elligeable for collection" ... > via the reference to the Command object which is held by the DataReader" ...
    (microsoft.public.dotnet.framework)
  • Re: Closing connections
    ... > you don't have to close a DataReader when binding it to a Grid or List. ... >>I have been misunderstanding the closing of the connection. ... >> This is a problem with my Database object. ... >> reader set to CommandBehavior.CloseConnection. ...
    (microsoft.public.dotnet.framework.adonet)