Keep your connection details in Application objects
Code:
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
'==Visual InterDev Generated - startspan==
'--Project Data Connection
Application("cn_ConnectionString") = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("..\DB\myDatabase.mdb") & ";Persist Security Info=False"
Application("cn_ConnectionTimeout") = 15
Application("cn_CommandTimeout") = 30
Application("cn_CursorLocation") = 3
Application("cn_RuntimeUserName") = "admin"
Application("cn_RuntimePassword") = ""
'==Visual InterDev Generated - endspan==
End Sub
</SCRIPT>
These can then be used like session objects anywhere in you pages without the need for server side includes. Call as follows for each ASP page requiring Database access:
Code:
' Create Objects
set cn = server.CreateObject("ADODB.Connection")
set rs = server.CreateObject("ADODB.Recordset")
rqs = "SELECT * FROM myTable WHERE myID = " & myValue
' Open Connection
cn.Open Application("cn_ConnectionString")
' Set up Recordset
rs.CursorLocation = adUseClient
' Get required data
if Len(rqs) > 0 then
rs.Open rqs, cn, adOpenKeyset, adLockBatchOptimistic
'Proccess the data to HTML etc
end if
' Tidy Up
rs.Close
set rs=nothing
cn.Close
set cn=nothing
This will always allow you to keep your connection details without session objects (when client user has 'No Cookies' selected on their browser). The added advantage is that connections will be kept to a minimum (only on demand).