Methods for connecting DBF, DBC, MDB, Excel, SQL Server databases with asp:
ASP Object Access database method
In ASP, the object that accesses a database is called ADO (Active Data Objects), 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 or a data source to connect to each database, but I recommend that you use a driver because it's easy and easy to use, and it's cumbersome to use a data source.
ODBC links
Fit database type |
link |
access |
driver={microsoft access Driver (*.mdb)};d bq=*.mdb;uid=admin;pwd=pass; |
dBase |
"Driver={microsoft dBase Driver (*.dbf)};d riverid=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=pas s; " |
MS text |
"Driver={microsoft text Driver (*.txt; *.csv)};d bq=-----; extensions=asc,csv,tab,txt; Persist securityinfo=false; " |
Visual Foxpro |
driver={microsoft visual Foxpro driver};sourcetype=dbc;sourcedb=*.dbc; Exclusive=no; " |
MySQL |
"Driver={mysql}";d atabase=yourdatabase;uid=username;pwd=yourpassword;option=16386; " |
OLE DB links
Appropriate type of database |
Link Way |
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 ' " |
And we generally use Access database more, here I recommend that you connect to an Access database using the following methods:
Dim conn
Set conn = Server.CreateObject ("Adodb.connection")
Conn.Open = "Provider=Microsoft.Jet.OLEDB.4.0" & "Data Source =" & Server.MapPath (". /db/bbs.mdb ")
Which.. /db/bbs.mdb is the relative path of your database store. If your database and ASP files are in the same directory, you can just write this:
Dim conn
Set conn = Server.CreateObject ("Adodb.connection")
Conn.Open = "Provider=Microsoft.Jet.OLEDB.4.0" & "Data Source =" & Server.MapPath ("Bbs.mdb")
There are many beginners who have problems when they encounter a database connection, but using the driver above will not be a problem as long as your database path is selected.