ASP SQL Server Connection

前端 未结 2 1929
自闭症患者
自闭症患者 2021-01-17 07:45
 <%
 DIM objConn
 Set objConn = Server.CreateObject(\"ADODB.Connection\")
 objConn.ConnectionString = \"Data Source=123.123         


        
2条回答
  •  抹茶落季
    2021-01-17 08:47

    Dim rs, dbConn
    
    Function OpenDB()
        Set dbConn = Server.CreateObject("ADODB.Connection")
        dbConn.ConnectionTimeout = 300
        dbConn.CommandTimeout = 300
        dbConn.Open "Data Source=123.123.12.123,1234;Database=DatabaseName;User Id=Usernm;Password=abcd1234;"
    End Function
    
    Function CloseDB()
        Set rs = Nothing
        if ucase(TypeName(dbConn)) = "CONNECTION" then
            dbConn.Close
            Set dbConn = Nothing
        end if
    End Function
    
    Function OpenRecordSet(recset, tablename)
        Call OpenDB()
        Set recset = Server.CreateObject("ADODB.Recordset")
        recset.Open tablename, dbConn, 0, 1
    End Function
    
    Function CloseRecordSet(recset)
        Set recset = Nothing
        Call CloseDB()
    End Function
    

    Then use

    <%
    Call OpenDB()
    sql = "select from mytable where this = 'that'"
    Set rs = dbConn.Execute(sql)
    if not rs.EOF then
          ' do your stuff!
    end if
    Call CloseDB()
    %>
    

    http://www.shiningstar.net/articles/articles/database/datafunctions.asp?ID=AW

提交回复
热议问题