Closing connections

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



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

  • Re: Closing connections
    ... > entire rowset) is to close the DataReader post population. ... > only if) the Connection was closed when the Fill is executed, ... Would I need to put a close after each execution of RunProcedure (I assume ... Dim dbReader As SqlDataReader ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Closing connections
    ... Any control that fills itself with more than one row closes the DataReader. ... >> only if) the Connection was closed when the Fill is executed, ... > Also, what about this case, (RunProcedure returns a DataReader that sets ... >>> Dim dbReader as SqlDataReader ...
    (microsoft.public.dotnet.framework.adonet)
  • 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)