charon
11-28-2002, 05:20 AM
hi,
due to I have multiple databases my web-site, so it will be good if I can create a connection function which can be use for all the database.
Below is my coding, it seems like can't work. If declare all the connection variables (objDC, objRS..etc) inside the subroutine then it can't be used outside the subroutine. So, I declare it outside the subroutine. Does it correct?????? Please advice!
<!-- #Include file="ADOVBS.INC" -->
<%
dim objDC
dim objRS
dim objRS2
dim objRS3
Session.Timeout=720
Sub DbConnectionOpen(DataPath)
'Create and establish data connection
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.ConnectionTimeout = 15
objDC.CommandTimeout = 30
'Use this line to use Access
objDC.Open "DBQ=" & DataPath & ";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;MaxBufferSize=8192;Threads=20;uid=;pwd=1234"
' Create recordset and retrieve values using the open connection
End Sub
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objRS2 = Server.CreateObject("ADODB.Recordset")
Set objRS3 = Server.CreateObject("ADODB.Recordset")
with objRS
.ActiveConnection = objDC
.CursorLocation = adUseClient
.CursorType=adOpenDynamic
.LockType=adLockOptimistic
end with
with objRS2
.ActiveConnection = objDC
.CursorLocation = adUseClient
.CursorType=adOpenDynamic
.LockType=adLockOptimistic
end with
with objRS3
.ActiveConnection = objDC
.CursorLocation = adUseClient
.CursorType=adOpenDynamic
.LockType=adLockOptimistic
end with
call from other asp page:
DataPath = Server.MapPath("../../db/data1.mdb")
DbConnectionOpen DataPath
sSQL="SELECT * FROM TableName"
%>
How about using function??? How?? I failed to return the connection value! Please advice!
due to I have multiple databases my web-site, so it will be good if I can create a connection function which can be use for all the database.
Below is my coding, it seems like can't work. If declare all the connection variables (objDC, objRS..etc) inside the subroutine then it can't be used outside the subroutine. So, I declare it outside the subroutine. Does it correct?????? Please advice!
<!-- #Include file="ADOVBS.INC" -->
<%
dim objDC
dim objRS
dim objRS2
dim objRS3
Session.Timeout=720
Sub DbConnectionOpen(DataPath)
'Create and establish data connection
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.ConnectionTimeout = 15
objDC.CommandTimeout = 30
'Use this line to use Access
objDC.Open "DBQ=" & DataPath & ";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;MaxBufferSize=8192;Threads=20;uid=;pwd=1234"
' Create recordset and retrieve values using the open connection
End Sub
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objRS2 = Server.CreateObject("ADODB.Recordset")
Set objRS3 = Server.CreateObject("ADODB.Recordset")
with objRS
.ActiveConnection = objDC
.CursorLocation = adUseClient
.CursorType=adOpenDynamic
.LockType=adLockOptimistic
end with
with objRS2
.ActiveConnection = objDC
.CursorLocation = adUseClient
.CursorType=adOpenDynamic
.LockType=adLockOptimistic
end with
with objRS3
.ActiveConnection = objDC
.CursorLocation = adUseClient
.CursorType=adOpenDynamic
.LockType=adLockOptimistic
end with
call from other asp page:
DataPath = Server.MapPath("../../db/data1.mdb")
DbConnectionOpen DataPath
sSQL="SELECT * FROM TableName"
%>
How about using function??? How?? I failed to return the connection value! Please advice!