A large part of the learning program requires connection operations with the database. Here is a brief summary of some codes for asp connection access for the convenience of friends who need it. 1. Compared with older environments, it is recommended to use the second one
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. For machines with win2003 or above, it is recommended to use this method, which is more efficient.
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.
Build odbc source xxx
set conn=server.createobject(Adodb.connection)
conn.open DSN=xxx;UID=;PWD=;Database=customer
5. Attached is a commonly used database connection code for sqlserver and access.
Copy the code code 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
DataUser = jb51net 'Access database user name
DataBaseName = jb51net 'Database name
DataBasePsw = Password'Access database 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 Database connection error, please check the database parameter settings in the Conn.asp file. :Response.End
%>