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
Strconn = "driver = {SQL Server}; description = sqldemo; server = 127.0.0.1 ;"_
& "Uid = loginid; Password =; database = database_name"
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open strconn
Third
Strconn = "driver = {Microsoft Access Driver (*. 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: Example
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 first-this method is used in access
Strconn = "driver = Microsoft Access Driver (*. mdb); DBQ = "_
& Server. mappath ("aspfree. mdb ")
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open strconn
The following describes a database connection website, which is quite good.
Connectiong: http://tempuri.org/tempuri.html
ASP database connection code
'Solved the ACCESS database path problem!
'Use dbtype = 0 or dbtype = 1 to distinguish between the AC database and the MSSQL database.
'The precautions for using the AC library are described in the program.
-----------------------------------------------
Dim dbtype, Conn, strconn
Dbtype = 0' 0 indicates the ACCESS database, and 1 indicates the MSSQL database.
If (dbtype = 0) then
******************
Dim dbfoldername, dbfolder_path, sitefolder
Dbfoldername = "articledata" 'name of the folder where the database is located
Dbfolder_path = server. mappath (dbfoldername) 'database path
Sitefolder = "article" 'name of the root directory of the system
If SESSION ("rootdir") = "" then
Session ("rootdir") = mid (dbfolder_path, 1, instr (1, dbfolder_path, sitefolder, 1)-1) & sitefolder
End if
Set conn = server. Createobject ("ADODB. Connection ")
Strconn = "driver = {Microsoft Access Driver (*. MDB)}; DBQ = "& SESSION (" rootdir ") &" \ "& dbfoldername &" \ data. mdb "'connect to the database
Conn. Open strconn
'*************************************** ***********
Elseif (dbtype = 1) then
******
Dim dbuserid, dbpassword, dbname, dbip
'Modify the following information to suit your website
Dbuserid = "sa" 'database Login Name
Dbpassword = "" 'Database Password
Dbname = "dbname" 'Database Name
Dbip = "local" 'address of the database. If it is a local database, it is: (local)
Set conn = server. Createobject ("ADODB. Connection ")
Strconn = "provider = sqloledb.1; Data Source =" & dbip & "; initial catalog =" & dbname & "; persist Security info = true; user id =" & dbuserid &"; password = "& dbpassword &"; Connect timeout = 30"
Conn. Open strconn
'*************************************** ***************
Else
************* ****
Response. Write "database setup error. Please contact the administrator! "
Response. End
End if
'Response. Write strconn
'Solved the ACCESS database path problem!
'Use dbtype = 0 or dbtype = 1 to distinguish between the AC database and the MSSQL database.
'The precautions for using the AC library are described in the program.
-----------------------------------------------
Dim dbtype, Conn, strconn
Dbtype = 0' 0 indicates the ACCESS database, and 1 indicates the MSSQL database.
If (dbtype = 0) then
******************
Dim dbfoldername, dbfolder_path, sitefolder
Dbfoldername = "articledata" 'name of the folder where the database is located
Dbfolder_path = server. mappath (dbfoldername) 'database path
Sitefolder = "article" 'name of the root directory of the system
If SESSION ("rootdir") = "" then
Session ("rootdir") = mid (dbfolder_path, 1, instr (1, dbfolder_path, sitefolder, 1)-1) & sitefolder
End if
Set conn = server. Createobject ("ADODB. Connection ")
Strconn = "driver = {Microsoft Access Driver (*. MDB)}; DBQ = "& SESSION (" rootdir ") &" \ "& dbfoldername &" \ data. mdb "'connect to the database
Conn. Open strconn
'*************************************** ***********
Elseif (dbtype = 1) then
******
Dim dbuserid, dbpassword, dbname, dbip
'Modify the following information to suit your website
Dbuserid = "sa" 'database Login Name
Dbpassword = "" 'Database Password
Dbname = "dbname" 'Database Name
Dbip = "local" 'address of the database. If it is a local database, it is: (local)
Set conn = server. Createobject ("ADODB. Connection ")
Strconn = "provider = sqloledb.1; Data Source =" & dbip & "; initial catalog =" & dbname & "; persist Security info = true; user id =" & dbuserid &"; password = "& dbpassword &"; Connect timeout = 30"
Conn. Open strconn
'*************************************** ***************
Else
************* ****
Response. Write "database setup error. Please contact the administrator! "
Response. End
End if
'Response. Write strconn