1、OLE驱动方式
Dim conn,connstr,Db
Db = "data/dvbbs7.mdb"
ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(Db)
On Error Resume Next
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请检查连接字串。"'注释,需要把这几个字翻译成英文。
Response.End
End If
2、用DSN连接并且没有用户名和密码
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "YourDSNName"
3、用DSN连接并且有用户名和密码
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "YourDSNName","username","password"
4、用实际的数据库绝对路径连接(服务器版本较低时采用此种方式)
Dim conn,Strconn,Db
Db="e:\dvbbs\dvbbs.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
Strconn="DRIVER={Microsoft Access Driver (*.mdb)}; "
Strconn=Strconn & "DBQ=Db"
conn.Open Strconn
MS SQL Server数据库连接
1、用DSN连接
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "DSN=MyDSN;UID=user;PWD=password;DATABASE=databasename"
2、不用DSN连接:
Dim conn,Strconn
Set conn = Server.CreateObject("ADODB.Connection")
Strconn="DRIVER={SQL Server};SERVER=SName;UID=USER;PWD=pwd;DATABASE=DBname"
conn.open Strconn
3、SQL server OLE DB连接方法
Dim adocon
set adocon=Server.Createobject("adodb.connection")
adocon.open"provider=SQLOLEDB.1;Data Source=RITANT4;"& _
"user ID=***;Password=***;"& _
"inital Catalog=数据库名"
FoxPro数据库连接
Dim Conn,ConnStr
Set Conn = Server.CreateObject("ADODB.connection")
ConnStr= "Driver=Microsoft Visual Foxpro Driver; UID=uID;SourceType=DBC;SourceDB=D:\DB.dbc"
Conn.Open ConnStr
Oracle 连接方法
Dim adocon
set adocon=Server.Createobject("adodb.connection")
adocon.open"Driver={microsoft odbc for oracle};server=oraclesever.world;uid=admin;pwd=pass;"
Oracle OLE DB 连接方法
Dim adocon
set adocon=Server.Createobject("adodb.connection")
adocon.open"Provider=OraOLEDB.Oracle;data source=dbname;user id=admin;password=pass;"
DBase 连接方法:
Dim adocon
set adocon=Server.Createobject("adodb.connection")
adocon.open"Driver={microsoft dbase driver(*.dbf)};driverid=277;dbq=-----;"
mySQL 连接方法:
Dim adocon
set adocon=Server.Createobject("adodb.connection")
adocon.open"Driver={mysql};database=yourDB;uid=uid;pwd=pwd;option=16386;"
MS text 连接方法
Dim adocon
set adocon=Server.Createobject("adodb.connection")
adocon.open"Driver={microsoft text driver(*.txt; *.csv)};dbq=-----;"&_
"extensions=asc,csv,tab,txt;Persist SecurityInfo=false;"
MS text OLE DB 连接方法
Dim adocon
set adocon=Server.Createobject("adodb.connection")
adocon.open"Provider=microsof.jet.oledb.4.0;data source=your_path;"&_
"Extended Properties'text;FMT=Delimited'"