㈠ ASP连接数据库的连接方法
access的连接字符串
<%
db="数据库路径"
connstr="DBQ="+server.mappath(""&db&"")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
on error resume next
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
if err then
response.write err.discription
Err.Clear
conn.close
set conn=nothing
Response.Write "数据库连接出错,请检查连接字符串。"
Response.End
end if
%>
sqlser连接
<%
Sql_Server = "服务器地址"
Sql_User = "数据库账号"
Sql_Pass = "密码"
Sql_Data = "数据库名"
dim Conn,connstr
connstr = "PROVIDER=SQLNCLI;DATA SOURCE="&Sql_Server&";UID="&Sql_User&";PWD="&Sql_Pass&";DATABASE="&Sql_Data
set Conn = server.createobject("ADODB.connection")
Conn.open connstr
if err then
response.write err.discription
Err.Clear
conn.close
set conn=nothing
Response.Write "数据库连接出错,请检查连接字符串。"
Response.End
end if
%>