View Full Version : Include Database Conenction on each asp pages
charon
09-12-2002, 03:08 AM
hi,
since my web-site is a database driven, so most of the time it requires to create and establish data connection. Usually we will use Include Directive to include the connection.inc on top of asp pages which needed (as below)
<!--#include file="/include/ADODBConnection.inc"-->
Since most of the time, it requires data connection, so it causes the server to create and establish the connection so often, and became unefficiency. Can I made it global by creating the connection at global.asa by using Application Object????? have ever people use this way??? Please advice!!
Morgoth
09-12-2002, 03:09 PM
I don't know about that global.asa connection thing, you might have to look it up. http://aspin.com <-good source.
Another way could be if you need info you can make a bunch of submit pages, and include the connection to them only. then when everything is added, updated or selected, you can store it in a querystring, or a cookie, or something like that, and use it for the page you need.
Yeah, you may not like it, but if the global.asa search isn't found, you might want to try to open up connections only if you need to..
Also, what about closing the connection when you are done with it?
dfrancis
09-14-2002, 06:05 PM
Here is how Mr. Gates has implemented in Interdev for an Access db...
In the glabal asa file...
Sub Application_OnStart
'==startspan==
Dim UrlVars(1)
'--Project Data Connection
Application("Database1_ConnectionString") = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=URL=folder/file.mdb"
UrlVars(0) = "Database1_ConnectionString"
Application("Database1_ConnectionTimeout") = 15
Application("Database1_CommandTimeout") = 30
Application("Database1_CursorLocation") = 3
Application("Database1_RuntimeUserName") = ""
Application("Database1_RuntimePassword") = ""
'--
Application("UrlVars") = UrlVars
'==endspan==
End Sub
charon
09-16-2002, 02:58 AM
how about end the connection, where to end?? in the application on_end??
webmarkart
09-16-2002, 03:34 PM
I recommend making the connection on the main asp page. Open the connection on the top of default.asp for example and on the very bottom close it. All of your include files that need the connection will automatically have the connection already.
<%
action = Trim(Request("action"))
Response.Buffer = True
action = Trim(Request("action")) & ""
DataPathInfo = "d:\home\yoursite.com\data\database.mdb"
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " & DataPathInfo
Set oConn = Server.CreateObject ("ADODB.Connection")
oConn.Open strConnect
%>
<% If action = "" or action = "search" Then %>
<!--#include file="includes/listings_search.inc"-->
<% ElseIf action = "searchlist" Then %>
<!--#include file="includes/listings_search_list.inc"-->
<% ElseIf action = "industrial" Then %>
<!--#include file="includes/listings_industrial.inc"-->
<% End If %>
<%
oConn.CLOSE
Set oConn = Nothing
%>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.