Lukin

最近比较穷!

不错的数据库连接代码

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

 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


%>

阅读更多
个人分类: 资源分享
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭