Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Global Database connection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Spitfire - 02 Aug 2007 20:17 GMT
Hi,

I am trying to make a web application using C#. I need to access database in
every webpage and for that I have created new database connection each time.
This is not an efficient way at all.

Is it possible to have some kind of Global database object which we can
refer from any page? Or is there any alternate solution ?

thanks your help
Peter Bromberg [C# MVP] - 02 Aug 2007 20:36 GMT
Actually it is very efficient, since ADO.NET makes use of the Connection Pool
which is specifically designed to cache connection objects (up to 100 by
default) and provide them on demand. So, best-practices coding dictates that
you should create and open a new Connection object just before you do your
database work, and then close it and allow it to return to the pool
immediately afterward.

in C#, the using (                 ) {             }  statement construct
ensures that Close or Dispose is called automatically once the closing brace
is reached, even if an exception is thrown.
-- Peter
Recursion: see Recursion
site:  http://www.eggheadcafe.com
unBlog:  http://petesbloggerama.blogspot.com
bogMetaFinder:    http://www.blogmetafinder.com

> Hi,
>
[quoted text clipped - 6 lines]
>
> thanks your help
Mark Rae [MVP] - 02 Aug 2007 20:37 GMT
> I am trying to make a web application using C#. I need to access database
> in
> every webpage and for that I have created new database connection each
> time.
> This is not an efficient way at all.

Yes it is - it is *by far* the most efficient way you can do it.

> Is it possible to have some kind of Global database object which we can
> refer from any page?

This is one of the worst things you can do in ASP.NET in terms of
performance and scalability.

ADO.NET brings you connection pooling, so you should create your connection
at the very last moment and destroy it as soon as you no longer need it.

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.