Methods for connecting to five databases in ASP

Source: Internet
Author: User
Methods for connecting to databases in ASP

Five connections in ASPDatabaseMethod

First-this method is most used in access

Strconn = "driver = Microsoft Access Driver (*. mdb); DBQ =" & server. mappath ("aspfree. mdb ")

Set conn = server. Createobject ("ADODB. Connection ")

Conn. Open strconn

 

Second-this method is used in SQL Server

Dim Conn, conntol

Conntol = "driver = {SQL Server}; server = server name; uid = login account; Pwd = login password; database =DatabaseName"

Set conn = server. Createobject ("ADODB. Connection ")

Conn. Open conntol

Third

Strconn = "driver = {microsoftaccessdriver (*. mdb )};"&_

"DBQ = F: \ Inetpub \ wwwroot \ somedir \ db1.mdb; defaultdir = F: \ Inetpub \ wwwroot \ somedir;

& _ Uid = loginid ;"&_

"Pwd = password; driverid = 25; fil = msaccess;" set conn = server. Createobject ("ADODB. Connection ")

Conn. Open strconn

Fourth, using system data sources

The following uses a data source name:

Set conn = server. Createobject ("ADODB. Connection ")

Conn. Open "example"

Fifth, you must set the data source in ODBC on the control panel.

Set rs = server. Createobject ("ADODB. recordset ")

Rs. Open "tblname", "dsnname", 3, 3

Description of the constant number

Adopenforwardonly 0 starts a forward (Forward-only) cursor. The default value is

Adopenkeyset 1 start a keyset cursor

Adopendynamic 2 start a dynamic type cursor

Adopenstatic 3 Start a static cursor

The locktype parameter indicates the lock type used.

Description of the constant number

Adlockreadonly 1 is started in read-only mode and cannot run addnew, update, delete, and other methods. The default value is

Adlockpessimistic 2 when data is being updated, the system will temporarily lock other users
To ensure data consistency.

Adlockoptimistic 3 when data is being updated, the system will not temporarily lock other user actions

Adlockbatchoptimistic 4 when data is being updated, other users must set the cursorlocation attribute to adusebatchDatabaseOperation

The options parameter indicatesDatabaseRequest type.

Description of the constant number

The commandtext parameter specified by adcmdunknown-1 cannot be determined. The default value is

The commandtext parameter specified by adcmdtext 1 is a common command type.

The commandtext parameter specified by adcmdtable 2 is an existing table name.

The commandtext parameter specified by adcmdstoredproc 3 is the name of the stored procedure table.

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.