ASP調(diào)用SQL Server、Access數(shù)據(jù)庫代碼
—— 閱讀:13062次
1、ASP連接調(diào)用SQL Server數(shù)據(jù)庫的代碼:
Strconn="provider=sqloledb;datasource=數(shù)據(jù)庫服務(wù)器地址;uid=數(shù)據(jù)庫用戶名;pwd=數(shù)據(jù)庫密碼;datebase=數(shù)據(jù)庫名"
setconn=server.createobject("adodb.connection")
conn.open strconn
提示:如果數(shù)據(jù)庫與網(wǎng)站空間在同一臺服務(wù)器上,建議data source地址使用127.0.0.1或(local)
或者請參考一下代碼:
dim titlename
dim Strconn
titlename="數(shù)據(jù)庫連接測試"
Dim Conn,ConnStr,DataServer,DataBase,DataUser,DataPass
DataServer = "數(shù)據(jù)庫服務(wù)器地址"
DataBase = "數(shù)據(jù)庫名"
DataUser = "數(shù)據(jù)庫用戶名"
DataPass = "數(shù)據(jù)庫密碼"
ConnStr="Provider=SQLOLEDB.1;User ID="&DataUser&";Password="&DataPass&";Initial Catalog="&DataBase&";
Data Source="&DataServer&""
Set Conn=Server.CreateObject("ADODb.Connection")
Conn.ConnectionString=ConnStr
Conn.Open
2、在ASP中連接調(diào)用Access數(shù)據(jù)庫代碼:
Set conn=Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("/db/data.mdb")
提示:請您將"/db/data.mdb"替換為您自己的Access數(shù)據(jù)庫實際路徑。