ASP調(diào)用SQL Server、Access數(shù)據(jù)庫(kù)代碼
- 作者:新網(wǎng)
- 文章來源:新網(wǎng)
- 點(diǎn)擊數(shù):100
- 更新時(shí)間:2009-07-24 01:08:47
1、ASP連接調(diào)用SQL Server數(shù)據(jù)庫(kù)的代碼:
Strconn="provider=sqloledb;datasource=數(shù)據(jù)庫(kù)服務(wù)器地址;uid=數(shù)據(jù)庫(kù)用戶名;pwd=數(shù)據(jù)庫(kù)密碼;datebase=數(shù)據(jù)庫(kù)名"
setconn=server.createobject("adodb.connection")
conn.open strconn
提示:如果數(shù)據(jù)庫(kù)與網(wǎng)站空間在同一臺(tái)服務(wù)器上,建議data source地址使用127.0.0.1或(local)
或者請(qǐng)參考一下代碼:
dim titlename
dim Strconn
titlename="數(shù)據(jù)庫(kù)連接測(cè)試"
Dim Conn,ConnStr,DataServer,DataBase,DataUser,DataPass
DataServer = "數(shù)據(jù)庫(kù)服務(wù)器地址"
DataBase = "數(shù)據(jù)庫(kù)名"
DataUser = "數(shù)據(jù)庫(kù)用戶名"
DataPass = "數(shù)據(jù)庫(kù)密碼"
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ù)庫(kù)代碼:
Set conn=Server.CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("/db/data.mdb")
提示:請(qǐng)您將"/db/data.mdb"替換為您自己的Access數(shù)據(jù)庫(kù)實(shí)際路徑。