martin_narg
12-22-2004, 12:11 PM
All,
I am currently experiencing problems with trying to use a subroutine to create a generic database connection that i can call each time I require it.
My code is as follows:
sub getDBConnection(blnRecordset)
dbConnString = "Provider=SQLOLEDB;server=SERVER_ADDRESS;database=DATABASE;uid=USERID;password=PASSWORD;"
set objConn = Server.CreateObject("ADODB.Connection")
objConn.CommandTimeOut = 100
objConn.Open dbConnString
if blnRecordset then
set objRs = server.CreateObject("ADODB.Recordset")
else
set objCmd = Server.CreateObject("ADODB.Command")
objCmd.CommandTimeOut = 100
objCmd.ActiveConnection = objConn
response.write isobject(objCmd) & "<br>"
end if
end sub
call getDBConnection(false)
response.write isobject(objCmd)
Output is:
true
false
As shown by the output, the Command object is created in the sub but not available immediately after on the page itself. The code works flawlessly without the use of a sub - it is only when enclosed within the subroutine I am experiencing this problem.
If anyone has an idea why this is happening, I'd be very grateful for a response.
Many thanks for your time
Martin
I am currently experiencing problems with trying to use a subroutine to create a generic database connection that i can call each time I require it.
My code is as follows:
sub getDBConnection(blnRecordset)
dbConnString = "Provider=SQLOLEDB;server=SERVER_ADDRESS;database=DATABASE;uid=USERID;password=PASSWORD;"
set objConn = Server.CreateObject("ADODB.Connection")
objConn.CommandTimeOut = 100
objConn.Open dbConnString
if blnRecordset then
set objRs = server.CreateObject("ADODB.Recordset")
else
set objCmd = Server.CreateObject("ADODB.Command")
objCmd.CommandTimeOut = 100
objCmd.ActiveConnection = objConn
response.write isobject(objCmd) & "<br>"
end if
end sub
call getDBConnection(false)
response.write isobject(objCmd)
Output is:
true
false
As shown by the output, the Command object is created in the sub but not available immediately after on the page itself. The code works flawlessly without the use of a sub - it is only when enclosed within the subroutine I am experiencing this problem.
If anyone has an idea why this is happening, I'd be very grateful for a response.
Many thanks for your time
Martin