Hi
I am looking at the starter kits from asp.net 1.1. I have read that a
datareader returned from a DAL should be closed. In the code below,
copied from the Commerce starter kit, how would the datareader be
closed? I know there is a .close() command, but where would it go.
Thanks
----------------
DAL
----------------
Public Function GetProductCategories() As SqlDataReader
' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New
SqlCommand("CMRC_ProductCategoryList", myConnection)
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Execute the command
myConnection.Open()
Dim result As SqlDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
' Return the datareader result
Return result
End Function
---------------
.aspx page
---------------
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Obtain categoryId from QueryString
Dim categoryId As Integer = CInt(Request.Params("CategoryID"))
' Obtain products and databind to an asp:datalist control
Dim productCatalogue As ASPNET.StarterKit.Commerce.ProductsDB = New
ASPNET.StarterKit.Commerce.ProductsDB()
MyList.DataSource = productCatalogue.GetProducts(categoryId)
MyList.DataBind()
End Sub
Alexey Smirnov - 09 Jun 2007 11:49 GMT
On Jun 9, 11:56 am, m.fis...@uku.co.uk wrote:
> Hi
>
[quoted text clipped - 46 lines]
>
> End Sub
you have to close it
((SqlDataReader)MyList.DataSource).Close();
Alexey Smirnov - 09 Jun 2007 12:01 GMT
> On Jun 9, 11:56 am, m.fis...@uku.co.uk wrote:
>
[quoted text clipped - 54 lines]
>
> - Show quoted text -
brrr... sorry, you can close it, but it's already closed after it has
been bound to the control. Connection will be closed as well because
of CommandBehavior.CloseConnection
Mark Rae - 09 Jun 2007 12:22 GMT
> but it's already closed after it has been bound to the control.
You're correct - please ignore my previous post...

Signature
http://www.markrae.net
Mark Rae - 09 Jun 2007 12:02 GMT
> I have read that a datareader returned from a DAL should be closed.
Most definitely!
> In the code below, copied from the Commerce starter kit, how would the
> datareader be closed? I know there is a .close() command, but where would
> it go.
> MyList.DataSource = productCatalogue.GetProducts(categoryId)
> MyList.DataBind()
((SqlDataReader)MyList.DataSource).Close();

Signature
http://www.markrae.net