I have a grid which I populate by using a sqldatareader.
grdSelector.DataSource = GetSource(blah)
My GetSource consists of this, which returns a SqlDataReader
Dim dr As SqlDataReader = Nothing
Dim sql As String = GetQuery(Blah)
Dim con As New SqlConnection(Name.GetConnectionString)
Dim cmd As New SqlCommand(sql.ToString(), con)
cmd.CommandType = CommandType.Text
cmd.CommandTimeout = 600
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection) ' close the connection when the reader is closed
Okay, so I set my reader to CloseConnection when the reader is closed. But when is the reader closed?
I am populating my grid with it using the grid.DataSource, but when is the reader closed? Is it automatically closed when the user leaves the page? Or do I need to specifically close that reader somewhere? If so, where and how?