不错的数据库连接代码

<% '---------------------------------参数设置

 Function Get_Access_Conn(FileName,Password)     
       dim str
       on error resume next
       str= "Provider=Microsoft.Jet.OLEDB.4.0;"
       str=str& "Data Source=" &server.MapPath(FileName)&";Jet OLEDB:Database Password="&Password

      Set Get_Access_Conn= Server.CreateObject("ADODB.Connection")
      Get_Access_Conn.Open str  
   if err.number<>0 then
      Set Get_Access_Conn=nothing
   Get_Access_Conn="error"
  end if
End Function


function checkFileExist(filename)
      dim objFSO
   checkFileExist=false
   set objFSO=Server.CreateObject("Scripting.FileSystemObject")
   if objFSO.FileExists(server.MapPath(filename)) then
        checkFileExist=true
   end if
   set objFSO=nothing
end function

Function Get_Conn()
     on error resume next
  err.clear

    if checkFileExist("admin/include/sub/check.mdb") then
     path="admin/include/sub/"
    elseif checkFileExist("include/sub/check.mdb") then
     path="include/sub/"
 elseif checkFileExist("check.mdb") then
    path=""
 elseif checkFileExist("../include/sub/check.mdb") then
    path="../include/sub/"
 elseif checkFileExist("../../include/sub/check.mdb") then
    path="../../include/sub/"
 end if
 filename=path&"check.mdb"
 pwd=base64decode(base64decode("WjNWdmVYVnhhV0Z1Wnc9PQ=="))
      
  Set Get_Conn=Get_Access_Conn(filename,Pwd)
  if err.number<>0 then
   Response.Write "<script language=javascript>"
   Response.Write "alert('不能打开数据库!');"
   'Response.Write "window.history.back(1);"
   Response.Write "</script>"
   response.End()
  end if
End Function

function CloseConn(cn)
  if  IsObject(Session(cn))  then
       Session(cn).close
    set  Session(cn) =nothing
 end if
     session.Contents.Remove(cn)
end function


If IsObject(Session("Conn")) and Not IsNull(Session("Conn") ) Then
   Set  Conn = Session("Conn")                   
Else
     Set Conn =Get_Conn()
   Session("Conn") = Conn                 
end  if

Function Get_Rs(conn,sql,CursorType,LockType)
   on error resume next
   Set Get_Rs= Server.CreateObject("ADODB.Recordset")
 Get_Rs.Open sql, conn,CursorType,LockType
 if err.number<>0 then
    response.write sql&"<br>"
    response.write err.description
    response.End()
 end if
end Function


%>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值