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:
Output is:Code: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)
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.Code:true false
If anyone has an idea why this is happening, I'd be very grateful for a response.
Many thanks for your time