Opening Connections...

Results 1 to 2 of 2

Thread: Opening Connections...

  1. #1
    Sean Malloy Guest

    Default Opening Connections...

    Hi, <BR><BR>Myself and the other ASP Programmer here have been wondering about the following question...<BR><BR>We were recently seeking hosting for one of our clients, and were reading the T&C&#039s for the site.. It basically said, please use only one database connection per site, anything higher and you ..blah blah<BR><BR>Anyway, the standard way I do things, is open a database connection at the start of a page, and close it at the end.. but if 5 people load the same page, the connection is opened 5 times right?<BR><BR>Could you, for arguments sake, use the global.asa, and for example, use Application_OnStart, to open a single connection to the database, and throughout the site, use that, and then Application_OnEnd, close the database connection?<BR><BR>I&#039m not sure if I&#039ve made myself clear here.. but that would effectively create only one database connection yes? one that is opened when the webserver starts, and closed when the webserver is shutdown..<BR><BR>Is that a really bad thing to do?<BR><BR>I dunno, I&#039m new to all this =<BR><BR>Regards,<BR><BR>Sean<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Opening Connections...

    dear friend.<BR><BR>Don&#039t open the database connection in the application on_start<BR>event instead open the database in session_onstart.<BR><BR>Application_Onstart event will fire only once, when the<BR>very first user access your site.<BR><BR>open and close the connection in each and every page.<BR><BR>make use of the below code.<BR><BR><BR><BR>Sub Session_OnStart &#039 Runs the first time a user runs any page in your application<BR><BR> &#039Create an ADO Connection<BR> Set cn = Server.CreateObject("ADODB.Connection")<BR> <BR> &#039 Specify the OLE DB provider.<BR> cn.Provider = "sqloledb"<BR><BR> &#039 Specify connection string on Open method.<BR> &#039 To run the sample, edit this line to reflect your server&#039s name.<BR> ProvStr = "Server=Your_SQL_Server_Name;Database=Northwind;UI D=sa;PWD=;"<BR> cn.Open ProvStr<BR><BR> Set Session("cnn") = cn<BR><BR>END Sub<BR><BR>with regards<BR>venki.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts