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.