Connecting to the database in ASP (connection string)

Source: Internet
Author: User
First, the principle of access to the database
In ASP, the objects used to access the database are collectively called ADO objects (Active Data Objects), which contains three objects: Connection, Recordset, and command, where Connection is responsible for opening or connecting to the database. The recordset is responsible for accessing the data tables, command is responsible for executing the actions query (action queries) commands on the database and executing the stored Procedure of SQL Server. You must also have database-accessible drivers, OLE DB drivers, and ODBC drivers that rely on only these three objects or cannot access the database. An ADO object can access a database for any database that must have a corresponding OLE DB driver and ODBC driver.
ADO objects must be combined with a variety of drivers to access various types of databases, and different databases require different drivers. In Windows 9x/nt, "start" → "settings" → "Control Panel" → "ODBC Data Source (32Bit)" In the "Driver" tab, you can verify what drivers are installed on the machine.
Second, connect the database and open the data table
The methods of connecting different databases (that is, to establish connection instances are different), but the method of accessing data using the Recordset object is much the same when the connection instance is established. The following for different data types, write the corresponding connection function, in the program directly referenced.
The program is written in VB Script scripting language.
1. Establish the Mdbrecordset object. The MDB database is a complete database that may contain several data tables, in which the connection function is to connect the database, and the recordset is to open the datasheet.
Function createmdbrecordset (database file name, data table name, or SELECT statement)
Dim Conn,provider,dbpath
' Create a Connection object
Set conn = Server.CreateObject ("ADODB. Connection ")
Provider= "Provider=Microsoft.Jet.OLEDB.4.0;"
DBPath = "Data source=" & Server.MapPath ("Database filename")
' Open the Database
Conn. Open Provider & DBPath
Set Createmdbrecordset = Server.CreateObject ("ADODB. Recordset ")
' Open Data table
Createmdbrecordset.open "datasheet name", Conn, 2, 2
End Function
2. Create a Recordset object with a password MDB database. It is built like a Recordset object that creates an MDB database without a password, but one more password parameter, that is, the password information must be given when connecting to the database.
Function createsecuredmdbrecordset (database file name, data table name or SELECT statement, password)
Dim Conn,provider,dbpath
' Create a Connection object

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.