不用odbc的数据库连接代码(access)

      班门弄斧 2005-9-23 15:34
<%
Const db_Type = 1 '1为Access数据库,2为SQL数据库
Public Conn
If db_Type = 1 Then
Call db_Access("..\DataBase\20050506.mdb")
Else
Call db_SQL("sa","","202.103.61.123","db")
End If
'**************************************************
'函数名:db_Access
'作 用:打开Access数据库
'参 数:db_Name-----数据库名
'返回值:无
'**************************************************
Function db_Access(db_Name)
Dim Connstr
On Error Resume Next
Set Conn =Server.CreateObject("ADODB.Connection")
Connstr =Server.MapPath(db_Name)
'Conn.Open "DBQ="& Connstr &";DRIVER={Microsoft Access Driver (*.mdb)};pwd=a" '加密后的数据库打开
Conn.Open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source ="& Connstr '普通的数据库打开
If Err Then
Response.Redirect("../Public/Error.asp?ErrMsg="& Err.Description &"&ErrNo="& Err.Number)
Err.Clear
Response.End()
End If
End Function

'**************************************************
'函数名:db_SQL
'作 用:打开SQL数据库
'参 数:db_UserName-用户名,db_UserPwd-用户密码,
' db_Server-数据库IP,db_Name数据库名
'返回值:无
'**************************************************
Function db_SQL(db_UserName,db_UserPwd,db_Server,db_Name)
Dim ConnStr
On Error Resume Next
ConnStr = "Driver={SQL SERVER};server=" & db_Name & ";uid=" & db_UserName & ";pwd=" & db_UserPwd & ";database=" & db_Name & ";"
Set Conn = Server.CreateObject("Adodb.Connection")
Conn.Open ConnStr
If Err Then
Response.Redirect("../Public/Error.asp?ErrMsg="& Err.Description &"&ErrNo="& Err.Number)
Err.Clear
Response.End()
End If
End Function
%>
原帖来自于网易社区:http://p5.club.163.com/viewArticleByWWW.m?boardId=asp&articleId=asp_1066281eb6b00bd
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}