Data | database
Methods for connecting DBF, DBC, MDB, Excel, SQL Server databases with asp:
ASP Object Access database method
In ASP, the object that accesses the database is called ADO (Activedataobjects), contains three kinds of objects mainly: Connection, Recordset, Command
Connection: Responsible for opening or connecting data
Recordset: Responsible for accessing data tables
Command: Responsible for performing action query commands on the database
Two, the connection each database driver
You can use a driver to connect to each database, or you can use a data source, and we recommend that you use a driver.
ODBC links
Suitable for database type/link mode
"Driver={microsoftaccessdriver (*.mdb)};d bq=*.mdb;uid=admin;pwd=pass;"
"Driver={microsoftdbasedriver (*.dbf)};d riverid=277;dbq=------------;"
"Driver={microsoftodbcfororacle};server=oraclesever.world;uid=admin;pwd=pass;"
"Driver={sqlserver};server=servername;database=dbname;uid=sa;pwd=pass;"
"Driver={microsofttextdriver (*.txt;*.csv)};d bq=-----; extensions=asc,csv,tab,txt; Persistsecurityinfo=false; "
"DRIVER={MICROSOFTVISUALFOXPRODRIVER};SOURCETYPE=DBC;SOURCEDB=*.DBC; Exclusive=no; "
"Driver={mysql};d atabase=yourdatabase;uid=username;pwd=yourpassword;option=16386;"
OLE DB links
Suitable for database type/link mode
"Provider=microsoft.jet.oledb.4.0;datasource=your_database_path;userid=admin;password=pass;"
"Provider=oraoledb.oracle;datasource=dbname;userid=admin;password=pass;"
"Provider=sqloledb;datasource=machinename;initialcatalog=dbname;userid=sa;password=pass;"
"Provider=microsof.jet.oledb.4.0;datasource=your_path; ExtendedProperties ' text; Fmt=delimited ' "
The following is an example of a database that connects to access
Dimconn
Setconn=server.createobject ("Adodb.connection")
Conn.open= "Provider=Microsoft.Jet.OLEDB.4.0;" & "Datasource=" &server.mappath ("... /db/bbs.mdb ")
Which.. /db/bbs.mdb the relative path for the database! If the database and ASP files are in the same directory, this is all you need to write:
Dimconn
Setconn=server.createobject ("Adodb.connection")
Conn.open= "Provider=Microsoft.Jet.OLEDB.4.0;" & "Datasource=" &server.mappath ("Bbs.mdb")
There are many beginners who have problems when they encounter a database connection, but using the driver above will not cause problems as long as the database path is selected.