A newbie's dilemma
If opening a connection is resource intensive, and with ASP.Net we have to explicitly close a connection, when is it best to open and close?
Of course, if you have just one procedure that retrieves data for display, then this is a non-issue, as you would open, retrieve and close in that procedure.
Suppose you had several procedures in a page that needed access to the database?
Well, you get the idea.
Would it be best to open and close once? If so, should this be done in the Page_Load/Page_Unload events?
Or would it be more efficient to open and close in each of the procedures that requires access, which would be resource intensive?
Then again, the code to open and close the connection should be common to all pages so that we need not write the code in every page. Is there a way to do this?
Any guidance or pointers would be very much appreciated.
Thanks in advance
If opening a connection is resource intensive, and with ASP.Net we have to explicitly close a connection, when is it best to open and close?
Of course, if you have just one procedure that retrieves data for display, then this is a non-issue, as you would open, retrieve and close in that procedure.
Suppose you had several procedures in a page that needed access to the database?
Code:
Sub Page_Load()
DisplayThis()
End Sub
Sub DisplayThis()
Retrieve and display options
If Option selected
DisplayThat
End If
End Sub
Sub DisplayThat
Retrieve and display option values
End Sub
Well, you get the idea.
Would it be best to open and close once? If so, should this be done in the Page_Load/Page_Unload events?
Or would it be more efficient to open and close in each of the procedures that requires access, which would be resource intensive?
Then again, the code to open and close the connection should be common to all pages so that we need not write the code in every page. Is there a way to do this?
Any guidance or pointers would be very much appreciated.
Thanks in advance