asp對象化之:資料庫操作類

來源:互聯網
上載者:User
對象|資料|資料庫 <% 
’────────────────────────────────  
’功能說明:db類是實現資料庫連接的類,裡面留有資料庫連接字串介面 
’包括模組:無,一般都是被其他模組包括 
’調用方法:1、如果使用原有資料庫連接,則不用更改資料庫連接字串ConnStr 
’             具體操作為:Set DBC=New DataBaseClass 
’                         DBC.ConnStr="其他連接字串" 
’          2、方法使用:Set Conn=DBC.OpenConnection()得到一個連線物件 
’────────────────────────────────  
Class dbclass 
’────────────────────────────────  
’定義變數  
Private IConnStr  
’────────────────────────────────  
’ ConnStr屬性 
Public Property Let ConnStr(Val) 
    IConnStr = Val 
End Property 
’────────────────────────────────  
’ ConnStr屬性  
Public Property Get ConnStr() 
    ConnStr = IConnStr 
End Property 
’────────────────────────────────  
’ 類初始化  
Private Sub Class_initialize()  
End Sub  
’────────────────────────────────  
’ 類登出  
Private Sub Class_Terminate()  
    ConnStr = Null  
End Sub  
’────────────────────────────────  
’ 建立一個串連  
Public Function OpenConnection()  
    Dim TempConn 
    ’On Error Resume Next 
    Set TempConn = Server.CreateObject("ADODB.Connection") 
    TempConn.Open ConnStr  
    Set OpenConnection = TempConn  
    Set TempConn = Nothing  
    if Err.Number <> 0 then 
        Response.Write("<script>alert(’[系統錯誤]\n\n資料庫連接錯誤!請檢查系統參數設定>>網站常量設定,或者/inc/const.asp檔案!’);</script>")   
        Response.End 
    end if 
End Function  
End Class 

%> 



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.