DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Thu, 2 Aug 2007 14:17:11 -0500,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    Spitfire
          2    Peter Bromberg [C# MVP]
          3    Mark Rae [MVP]


Global Database connection   
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
Date:Thu, 2 Aug 2007 14:17:11 -0500   Author:  

RE: Global Database connection   
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



"Spitfire" wrote:


> 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
> 
Date:Thu, 2 Aug 2007 12:36:00 -0700   Author:  

Re: Global Database connection   
"Spitfire"  wrote in message 
news:E7E48663-233B-4361-B7A8-6830D5BADAAF@microsoft.com...


> 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.


-- 
Mark Rae
ASP.NET MVP
http://www.markrae.net
Date:Thu, 2 Aug 2007 20:37:24 +0100   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us