Normal Practice....

W

Wilson Smith

Microsoft document says use the Page_Unload event to perform final cleanup
work.

Like, closing files, closing database connections.

Considering the performance of the application is it always a good idea to
open the database connection at the Page_Load and do all the work and close
the connection in the Page_Unload event? Currently for each routine in its
specific function/sub routine I am opening the database connection and
closing.

I am just curious what the normal practice in the industry is in this
scenario.

Thanks for your reply.

Will
 
C

Curt_C [MVP]

open and close as necessary, explicitly. Dont rely on the unload to do it.
That's my "normal way"
 
M

Marina

I agree with Curt. It's good practice to get into the habit of closing
resources after you are done.

Besides, some day your functions may end up in a class library, in which
case it will all become more difficult for you to have page_unload take care
of everything.
 
K

Kevin Spencer

I wouldn't recommend having any database or IO code in your Pages. The Page
class is your Interface layer. It should only call upon business classes to
do the actual work, and contain interface-related code. For example, let's
say that you want to display data from a database in a DataGrid on the Page.
You could create a Database class having a method that can execute a
database operation and return a DataSet. The Page class can then call the
method in that class to get the DataSet, and simply bind it to the DataGrid.
The Database class would maintain its own connections.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top