ASP网站,用VB写DLL。Private Sub Class_Initialize()
 '代码略
 aspShow
End SubPrivate Sub Class_Terminate()
 Conn.Close
 Set Conn = Nothing
End Subpublic sub aspShow()
  Set Conn = Server.CreateObject("ADODB.Connection")
  Conn.Open ConnStr'连接数据库
  if... then
    Conn.Close '这句需要吗?
    Set Conn = Nothing‘这句需要吗?
    exit sub
  end if
end sub请问:Class_Terminate()已有关闭数据库连接的语句,那么过程aspShow()中if条件内的关闭数据库连接的两句需要写吗?

解决方案 »

  1.   

    Set Conn = Server.CreateObject("ADODB.Connection")
      Conn.Open ConnStr'连接数据库
    应该写在 Class_Initialize() 中,这样就不用每个方法里写了.
      

  2.   

    一般是用到时打开,不用了立即关闭,关闭时一般要判断一下:if... then 
        If Not Conn Is Nothing Then
            If Conn.State<>0  Then Conn.Close 
            Set Conn = Nothing
        End If
    ......Private Sub Class_Terminate()
        If Not Conn Is Nothing Then
            If Conn.State<>0  Then Conn.Close 
            Set Conn = Nothing
        End If
    End Sub
      

  3.   

    需要啊。╭═══════════════════╮
    ║ 免费的源码、工具网站,欢迎大家访问!║
    ║ http://www.j2soft.cn/        ║
    ╰═══════════════════╯