Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 10th, 2007, 04:05 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I usually refer to this as the bankrobbers 3G rule:

Go in, Get what you want and Get out....

The idea here is that you open the connection as late as possible, use it for the shortest possible time, and close it as soon as you're done.

There's no point in opening a connection if you're not going to use it. Connections are a scarce resource, and should be treated as such. Since connection pooling takes away much of the performance hit of creating a connection, you'll find generally that opening and closing it more than once on a single page doesn't hinder performance. Obviously, if you perform two or more data operations in a single call, you might as well let them share the connection.

From an OO and maintenance point of view, yo could let each function create its own connection object, open it and close it when it's done. If you want to pass DataReaders back from methods, you can use CommandBehavior.CloseConnection to indicate the connection must be closed when the reader is done reading.

For more info, take a look here: http://msdn2.microsoft.com/en-us/library/ms998569.aspx
It's a bit old, but it still applies....

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Which is better Datareader or Dataset. akhilhp ASP.NET 2.0 Basics 4 April 10th, 2007 04:43 AM
Converting a untyped dataset to a typed dataset daphnean Visual Studio 2005 0 July 13th, 2006 01:16 AM
Re: SQL Server dataset to ACCESS dataset dazzer ADO.NET 0 March 22nd, 2004 05:28 AM
Using DataReader() aadz5 ASP.NET 1.0 and 1.1 Basics 12 November 21st, 2003 06:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.