Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

connection lost with gobal.asa Application_OnStart

Status
Not open for further replies.
Sep 21, 2000
12
US
Global.asa has:
Sub Application_OnStart
Set CWconn = CreateObject("ADODB.Connection")
CWconn.ConnectionString = "uid=user;pwd=pass;DSN=CivilWar;"
CWconn.Open
Application("CivilWarConn") = CWconn

And my asp pages use this:
<%@ LANGUAGE=&quot;JAVASCRIPT&quot; %>
<%
var recordSet = Server.CreateObject(&quot;ADODB.RecordSet&quot;);
var CWconnection = Application(&quot;CivilWarConn&quot;);

and I use the connection later like this:
recordSet.Open(sql,CWconnection);

but some days the CWconnection is &quot;undefined&quot;. Is a constant connection &quot;thru Application_OnStart and closed in Application_OnEnd&quot; a bad practice?

If this practice is OK, what is a good error solution?
if((&quot;&quot;+CWconnection ) == &quot;undefined&quot;) {reconnect}

Instead of hand coding the solution function in every page... Can I create a solution function in global.asa? Do I just make an include file with the solution and call the include from every asp page? Any good suggestions out there?


David Kirchner
davidkirchner@yahoo.com
 
It is NOT a good to keep a connection open to a database for the whole time an application is loaded in memory.

Create an include file (with an .asp extension) and put a couple of functions in this file that will create connection and command objects, you could also have a function that destroys these objects once they are finished with. For example

Sub openConnAndComm(strConnName,strCommName)

Set strConnName = Server.CreateObject(&quot;ADODB.Connection&quot;)

strConnName.ConnectionTimeout = 100 ' your choice
strConnName.CommandTimeout = 100 ' your choice
strConnName.ConnectionString=&quot;uid=user;pwd=pass;DSN=CivilWar;&quot;

on error resume next

strConnName.Open

if Err.number <> 0 then
Session(&quot;LoginFailure&quot;) = &quot;true&quot;
else
Session(&quot;LoginFailure&quot;) = &quot;false&quot;
Set strCommName = Server.CreateObject(&quot;ADODB.Command&quot;)
Set strCommName.ActiveConnection = strConnectionName
end if

End Sub


Sub Close_Connection(strConnName,strCommName)
set strCommName = nothing
set strConnName = Nothing
end sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top