ADO related knowledge In ASP, the objects used to access the database are collectively called ADO (Active Data Objects), which mainly include three objects: Connection, Recordset, and Command.
Connection: Responsible for opening or connecting data
Recordset: Responsible for accessing data tables
Command: The driver responsible for executing action query commands on the database to connect to each database. You can use the driver (OLEDB) or the data source (ODBC) to connect to each database. Relatively speaking, using OLEDB is more convenient and simple.
ODBC link (the red bold part is the database type, and the right side is the related connection method)
access "Driver={microsoft access driver(*.mdb)};dbq=*.mdb;uid=admin;pwd=pass;"
dBase "Driver={microsoft dbase driver(*.dbf)};driverid=277;dbq =----------------;"
Oracle "Driver={microsoft odbc for oracle};server=oraclesever.world;uid=admin;pwd=pass;"
MSSQL server "Driver={sql server} ;server=servername;database=dbname;uid=sa;pwd=pass;"
MS text "Driver={microsoft text driver(*.txt; *.csv)};dbq=-----;extensions=asc, csv,tab,txt;Persist SecurityInfo=false;"
Visual Foxpro "Driver={microsoft Visual Foxpro driver};sourcetype=DBC;sourceDB=*.dbc;Exclusive=No;"
MySQL "Driver={mysql};database=yourdatabase ;uid=username;pwd=yourpassword;option=16386;"
OLEDB link
access "Provider=microsoft.jet.oledb.4.0;data source=your_database_path;user id=admin;password=pass;"
Oracle "Provider=OraOLEDB.Oracle;data source=dbname;user id=admin;password=pass;"
MS SQL Server "Provider=SQLOLEDB;data source=machinename;initial catalog=dbname;userid=sa;password=pass;"
MS text "Provider=microsof.jet.oledb.4.0;data source=your_path;Extended Properties'text; FMT=Delimited'"
The code related to connecting Access database in Asp can be written as:
Dim db,conn,connstr
db="data/hezepolice.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="DBQ="+server.mappath("db")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
'Adopt Oledb way
'connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
'Differences in string writing
'connstr="Driver={microsoft access driver (*.mdb)};DBQ=" & Server.MapPath(db)
'Use the previously established Dsn to connect
'connstr="dsn=hezepolice;"
conn.open connstr
The following is one of the common code methods used by Asp to establish a data connection when the database uses sqlserver.
Set conn=Server.CreateObject("ADODB.Connection")
on error resume next
connstr="Provider=SQLOLEDB;Password=***;Persist Security Info=True;User ID=sa;Initial Catalog=msdb;Data Source=localhost;Connect Timeout=15"
conn.Open connstr
Microsoft recommends using the following method when connecting to an Access database:
dim conn
set conn = server.createobject("adodb.connection")
conn.open = "provider=microsoft.jet.oledb.4.0;" & "data source = " & server.mappath("data.mdb")