主頁 > 知識庫 > ASP連接數(shù)據(jù)庫的全能代碼

ASP連接數(shù)據(jù)庫的全能代碼

熱門標簽:阿里云 電子圍欄 科大訊飛語音識別系統(tǒng) Mysql連接數(shù)設置 銀行業(yè)務 Linux服務器 團購網(wǎng)站 服務器配置
ASP連接數(shù)據(jù)庫的全能代碼     
'解決了ACCESS數(shù)據(jù)庫路徑的問題!
'采用DBType=0或DBType=1來區(qū)分AC庫還是MSSQL庫
'具體采用AC庫時應注意的事項,請看程序說明

--------------------------------------------------------------------------------
Dim DBType,Conn,StrConn
DBType=0        '0為Access數(shù)據(jù)庫,1為MSSQL數(shù)據(jù)庫 

If(DBType=0) Then
    '********************************ACCESS數(shù)據(jù)庫*************************************
    Dim DbFolderName,DbFolder_Path,SiteFolder
    DbFolderName="ArticleData"   '數(shù)據(jù)庫所在文件夾名稱
    DbFolder_Path = Server.MapPath(DbFolderName)   '數(shù)據(jù)庫所在路徑
    SiteFolder="Article"                    '系統(tǒng)所在根目錄名稱

    If Session("RootDir") = "" Then 
        Session("RootDir") = Mid(DbFolder_Path, 1, InStr(1,DbFolder_Path,SiteFolder,1) -1)  SiteFolder 
    End if
    Set Conn = Server.CreateObject("Adodb.Connection")
    StrConn = "Driver={Microsoft Access Driver (*.mdb)};DBQ="  Session("RootDir")  "\" DbFolderName  "\Data.mdb"  '連接到數(shù)據(jù)庫
    Conn.Open StrConn
    '**********************************************************************************
ElseIf(DBType=1) Then
    '*****************************MSSQL SERVER數(shù)據(jù)庫*************************************
    Dim DBUserID,DBPassWord,DBName,DBIP
    '修改以下信息以適合你的網(wǎng)站
    DBUserID="sa"  '數(shù)據(jù)庫登陸名
    DBPassWord=""  '數(shù)據(jù)庫密碼
    DBName="dbname" '數(shù)據(jù)庫名稱
    DBIP="local" '數(shù)據(jù)庫所在地址,如果是本地數(shù)據(jù)庫則為:(local)

    Set Conn=Server.CreateObject("Adodb.Connection")
    StrConn = "PROVIDER=SQLOLEDB.1;Data Source="DBIP";Initial Catalog="DBName";Persist Security Info=True;User ID="DBUserID";Password="DBPassWord";Connect Timeout=30"
    Conn.Open StrConn
    '**********************************************************************************
Else
    '***********************數(shù)據(jù)庫設置錯誤*************************************************
    Response.Write"數(shù)據(jù)庫設置錯誤,請聯(lián)系管理員!"
    Response.End
End If
'Response.Write StrConn 

 

標簽:萍鄉(xiāng) 蚌埠 衡水 棗莊 衢州 江蘇 大理 廣元

巨人網(wǎng)絡通訊聲明:本文標題《ASP連接數(shù)據(jù)庫的全能代碼》,本文關鍵詞  ;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266