Forum Moderators: open

Message Too Old, No Replies

including function

old asp

         

natty

3:04 pm on Jul 20, 2004 (gmt 0)

10+ Year Member



hi all,

im trying to functionise most of the parts of my asp report pages.
i have an include
<!--#INCLUDE FILE="functions.inc"-->


function dbConn()
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open("dsn=general")
end function
function getData(qry)
Set oRS=Server.CreateObject("ADODB.recordset")
set oRS = oConn.execute(qry)
arrRows = oRS.getrows()
getData = arrRows
end function

which to me seems fine, but ...
i call dbconn first , then when i call getData, im presented with the error.
Object required: 'oConn'

i thought all vars etc were public to all, and i had to turn them private if i didnt want that so.

obviously im missing something as always.
any help much appreciated.

nat

Easy_Coder

5:11 pm on Jul 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



oConn is local to dbConn(), seeing how dbConn() is not returning a value why not just make it a Public Sub versus a Function.

Public Sub dbConn()
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open("dsn=general")
End Sub

You'll also need a handler to close that connection too...

TheNige

8:00 pm on Jul 20, 2004 (gmt 0)

10+ Year Member



Just open and closer your connection in the getdata function. Open late/Close Early should be the rule.

duckhunter

10:57 pm on Jul 20, 2004 (gmt 0)

10+ Year Member



Or Dim oConn above your Include statement to declare the variable for the entire page.