Several Methods for connecting ASP to Access database

Source: Internet
Author: User

1. We recommend that you use the second one in a relatively old environment.
Set dbconnection = Server. CREATEOBJECT ("ADODB. CONNECTION ")
DBPath = Server. MapPath ("customer. mdb ")
Dbconnection. Open "driver = {Microsoft Access Driver (*. mdb)}; dbq =" & DBPath
SQL = "select * from auth where id = '" & user_id &"'"
SET uplist = dbconnection. EXECUTE (SQL)
2. We recommend that you use this method for win2003 and later machines to improve efficiency.
Set dbconnection = Server. CreateObject ("ADODB. Connection ")
DBPath = Server. MapPath ("customer. mdb ")
Dbconnection. Open "provider = microsoft. jet. oledb.4.0; data source =" & dbpath
SQL = "select * from auth where id = '" & user_id &"'"
SET uplist = dbconnection. EXECUTE (SQL)
3.
DBPath = Server. MapPath ("customer. mdb ")
Set session ("rs") = Server. CreateObject ("ADODB. Recordset ")
'Rs = Server. CreateObject ("ADODB. Recordset ")
Connstr = "provider = microsoft. jet. oledb.4.0; data source =" & dbpath
SQL = "select * from auth where id = '" & user_id &"'"
Session ("rs"). Open SQL, connstr, 1, 3
4.
Odbc source xxx
Set conn = server. createobject ("Adodb. connection ")
Conn. open "DSN = xxx; UID =; PWD =; Database = customer
5. Attach a commonly used SQL Server and access universal connection database code Copy codeThe Code is as follows: <%
Const DataBaseType = 1
If DataBaseType = 0 then
DBPath = "/jb51/news. asp"
SqlNowString = "Now ()"
Ystr = true
Nstr = false
Suiji = "rnd (id )"
Else
'If it is a SQL database, Please carefully modify the following database options
DataServer = "wwwjb51net" 'database Server IP Address
DataUser = "jb51net" 'user name for accessing the database
DataBaseName = "jb51net" 'Database Name
DataBasePsw = "password" 'database access password
SqlNowString = "getdate ()"
Ystr = 1
Nstr = 0
Suiji = "newid ()"
End if
On Error Resume Next
If DataBaseType = 1 Then
ConnStr = "driver = {SQL Server}; server =" & dataserver & "; UID =" & datauser & "; PWD =" & databasepsw & "; Database =" & databasename
Else
ConnStr = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" & Server. MapPath (DBPath)
End If
Set conn = Server. CreateObject ("ADODB. Connection ")
Conn. open ConnStr
If Err Then Err. Clear: Set conn = Nothing: Response. Write "the database connection fails. Check the database parameter settings in the Conn. asp file. ": Response. End
%>
Related Article

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.