关于VB6 没有用过,怎样在多个方法中共用一个 conn对向,是否可以初始化的时候先定义一下conn ?
Option ExplicitPrivate Context As ScriptingContext
Private Application As Application
Private Response As Response
Private Request As Request
Private Session As Session
Private Server As Server
Dim SUM As SinglePublic Sub OnStartPage(PassedscriptContext As ScriptingContext)
Set Context = PassedscriptContext
Set Application = Context.Application
Set Request = Context.Request
Set Response = Context.Response
Set Server = Context.Server
Set Session = Context.Session
SUM  = 3    
End Sub
Private Function RiskLoopNum(connstr)
    Dim sql As String
    Dim rsLoop, conn
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open (connstr)
    sql = "select count(*) as total from [RiskFactors] where ParentID=0"
    Set rsLoop = conn.Execute(sql)
    RiskLoopNum = Int(rsLoop("total") - 1)
    rsLoop.Close
    Set rsLoop = Nothing
    conn.Close
    Set conn = Nothing
End Function
Public Sub showsuc(connstr)
    Dim rs, conn
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open (connstr)
    
    Set rs = conn.Execute("Select * from [armUser]")
    Do While Not rs.EOF
        Response.Write (rs("Username"))
        rs.movenext
    Loop
    rs.Close
    Set rs = Nothing
    conn.Close
    Set conn = Nothing
End Sub
' 释放内部对象
Public Sub OnEndPage()
Set Application = Nothing
Set Request = Nothing
Set Response = Nothing
Set Server = Nothing
Set Session = Nothing
Set Context = Nothing
End Sub