asp连接db

来源:互联网 发布:压缩弹簧设计软件 编辑:程序博客网 时间:2024/05/16 09:58

<%
Sub LinkData100()
 set conn100 = server.createobject("adodb.connection")
 connstr = "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=user;password=pwd;Data Source=ora100" 
 conn100.open connstr
    If Err Then
     err.Clear
     Set conn100 = Nothing
     Response.Write "数据库连接出错,请检查连接字串。"
     Response.End
    End If
End Sub 

Sub CloseData100()
    if IsObject(conn100) then
        conn100.Close
        set conn100=nothing
    end if
End Sub

Sub LinkData101()
 set conn101 = server.createobject("adodb.connection")
 connstr = "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=user;password=pwd;Data Source=ora101" 
 conn101.open connstr
    If Err Then
     err.Clear
     Set conn101 = Nothing
     Response.Write "数据库连接出错,请检查连接字串。"
     Response.End
    End If
End Sub 

Sub CloseData101()
    if IsObject(conn101) then
        conn101.Close
        set conn101=nothing
    end if
End Sub

Sub Linksql()
 set connsql = server.createobject("adodb.connection")
 connstr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;pwd=q1aQtn;Initial Catalog=jiaoyou;Data Source=192.168.0.73"
 connsql.open connstr
    If Err Then
     err.Clear
     Set connsql = Nothing
     Response.Write "server73数据库连接出错,请检查连接字串。"
     Response.End
    End If
End Sub 

Sub Closesql()
    if IsObject(connsql) then
        connsql.Close
        set connsql=nothing
    end if
End Sub


Sub LinkDatamysql()
 Dim connstr,sql,rs,zy1,zy2,zy3
 connstr = "dsn=zymysql;driver={mysql odbc 3.51 driver};server=192.168.0.72;uid=user;pwd=pwd;database=ics_pageview"
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.open ConnStr
    If Err Then
     err.Clear
     Set Conn = Nothing
     Response.Write "数据库连接出错,请检查连接字串。"
     Response.End
    End If
End Sub 

Sub CloseData()
    if IsObject(conn) then
        conn.Close
        set conn=nothing
    end if
End Sub


Sub LinkData100()
 set conn100 = server.createobject("adodb.connection")
 'connstr = "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=user;password=pwd;Data Source=ora100" 
 connstr = "DRIVER={Oracle in orcclient};UID=user;PWD=pwd;DBQ=ora100;"
 conn100.open connstr
    If Err Then
     err.Clear
     Set conn100 = Nothing
     Response.Write "数据库连接出错,请检查连接字串。"
     Response.End
    End If
End Sub 

Sub CloseData100()
    if IsObject(conn100) then
        conn100.Close
        set conn100=nothing
    end if
End Sub

Sub LinkData101()
 set conn101 = server.createobject("adodb.connection")
 'connstr = "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;User ID=user;password=pwd;Data Source=ora101" 
 connstr = "DRIVER={Oracle in orcclient};UID=user;PWD=pwd;DBQ=ora101;"
 conn101.open connstr
    If Err Then
     err.Clear
     Set conn101 = Nothing
     Response.Write "数据库连接出错,请检查连接字串。"
     Response.End
    End If
End Sub 

Sub CloseData101()
    if IsObject(conn101) then
        conn101.Close
        set conn101=nothing
    end if
End Sub

Sub Linklob()
 Set OraSession=CreateObject("OracleInProcServer.XOraSession")
 Set connlob=OraSession.DbOpenDatabase("ora101","user/pwd",0)
    If Err Then
     err.Clear
     Set connlob = Nothing
     Set OraSession=nothing
     Response.Write "lob数据库连接出错,请检查连接字串。"
     Response.End
    End If
End Sub 

Sub Closelob()
    if IsObject(connlob) then
  Set connlob = Nothing
 Set OraSession=nothing
    end if
End Sub


Sub Linkaccess()
    Dim ConnStr
    DataType=0 '初始化数据库类型,0为Access,1为sql数据库
    If DataType=1 Then
        Dim SqlDatabaseName,SqlPassword,SqlUsername,SqlLocalName
        SqlDatabaseName = "bbsgood_speed"
        SqlPassword = "sa"
        SqlUsername = "sa"
        SqlLocalName = "127.0.0.1"
        ConnStr = "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlLocalName & ";"
    Else
        Dim Db,fso,path
        path="zy" '数据库目录名路径
        'Db="o92lacerintend.mdb" '数据库名
 Db="zy.mdb" '数据库名
        Db = ""&path&"/"&Db&""
        Set fso = Server.CreateObject("Scripting.FileSystemObject")
        if fso.FolderExists(server.MapPath(path))=false then
        Db="../"&Db
        end if
        set fso=nothing
     ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(db)
    End If
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.open ConnStr
    If Err Then
     err.Clear
     Set Conn = Nothing
     Response.Write "数据库连接出错,请检查连接字串。"
     Response.End
    End If
End Sub

%>

<%
Sub linkacc()
 dim connstr,db
 db="top10.mdb"
 Set conn = Server.CreateObject("ADODB.Connection")
 connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
 conn.Open connstr
end sub
%> 

原创粉丝点击