㈠ 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
%>