PDA

View Full Version : Calling procedures


bostjank
01-11-2003, 01:54 PM
Hi!

Can you tell me what's wrong with this script? I keep getting error

Microsoft VBScript runtime error '800a01a8'
Object required: 'conn'
/schoolgrad/test.asp, line 18


Am I not calling the procedure the right way? Or am I completely misunderstooding the role of procedures?

This is the code

<%
Sub ConnStart()
sConn = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source= " & Server.MapPath("db/database.mdb")
set conn = server.createobject("adodb.connection")
conn.open sConn
End Sub

Sub ConnOver()
conn.Close
set conn = Nothing
End Sub


sVir = Request.QueryString("1")

ConnStart()
sSQL = "INSERT INTO obiski(vir,datum,ura) VALUES('" & sVir & "','" & Date & "','" & Time & "')"
conn.Execute(sSQL)
ConnOver()

Response.Redirect "default.asp"
%>



Thanks for your help,
Bostjan

codefox
01-11-2003, 02:09 PM
Declare conn outside ConnStart(). Since you've set conn within the subroutine, it goes out of scope outside the function. Try compiling this:
<%
Dim conn
set conn = server.createobject("adodb.connection")

Sub ConnStart()
sConn = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source= " & Server.MapPath("db/database.mdb")
conn.open sConn
End Sub

Sub ConnOver()
conn.Close
set conn = Nothing
End Sub


sVir = Request.QueryString("1")

ConnStart()
sSQL = "INSERT INTO obiski(vir,datum,ura) VALUES('" & sVir & "','" & Date & "','" & Time & "')"
conn.Execute(sSQL)
ConnOver()

Response.Redirect "default.asp"
%>

whammy
01-11-2003, 03:38 PM
Actually I think all you need to do is Dim it outside the Sub(), you should be able to Set it inside the Sub() though.