How to use ASP to connect DBF, DBC, mdb, Excel, and SQL Server databases

Source: Internet
Author: User
Tags dbase dsn mssql server

Using ASP to connect to DBF, DBC, mdb, Excel, and SQL Server databases:
I. asp Object Access Database Method
In ASP, the objects used to access the database are collectively called ADO (Active Data Objects), which mainly contain three types of objects: connection, recordset, and command.
Connection: opens or connects data.
Recordset: used to access data tables.
Command: executes the action query command on the database.

2. Drivers connecting to various databasesProgram
You can use drivers or data sources to connect to different databases. However, we recommend that you use drivers because they are very convenient and simple, and it is troublesome to use data sources.

ODBC Link

Suitable for database type connection
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

Suitable Connection Methods for database types
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 '"

Excel "driver = {Microsoft Excel Driver (*. xls)}; DBQ =" & server. mappath ("test.xls ")

In general, there are many databases that use access. Here I suggest you use the following method to connect to the ACCESS database:

Dim Conn
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open = "provider = Microsoft. Jet. oledb.4.0;" & "Data Source =" & server. mappath ("../DB/BBS. mdb ")

Here, ../DB/BBS. mdb is the relative path of your database! If your database and ASP files are in the same directory, you only need to write them like this:

Dim Conn
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open = "provider = Microsoft. Jet. oledb.4.0;" & "Data Source =" & server. mappath ("bbs. mdb ")

Many beginners always encounter problems when encountering database connections. However, using the above driver will not cause problems if your database path is correct.

ASP and SQL database connectionCode:
Connstr = "driver = {SQL Server}; server = (local); uid = sa; Pwd =; database = infs ;"
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open connstr =
Set rs = server. Createobject ("adobd. recordset ")
SQL = "select * from Table order by ID DESC"
Rs. Open SQL, Conn, 3, 3

// Method 2: (DSN connection)

Connstr = "DSN = bbbs; uid = sa; Pwd = 12345"
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open connstr =
Set rs = server. Createobject ("adobd. recordset ")
SQL = "select * from Table order by ID DESC"
Rs. Open SQL, Conn, 3, 3 // 3, 3 is to modify, delete, add switch!

// Method 3:

Connstr = "driver = {SQL Server}; server = (local); uid = sa; Pwd = 11111; database = infs ;"
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open connstr

Asp and Excel connection
strdriver = "driver = {Microsoft Excel Driver (*. XLS)}; DBQ = "& server. mappath ("test.xls")
set objconn = server. createobject ("ADODB. connection ")
objconn. open strdriver
strselect = "select * from [sheet1 $]"
set objrs = server. createobject ("ADODB. recordset ")
objrs. open strselect, objconn

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.