学習プログラムの大部分では、データベースとの接続操作が必要です。必要な友人の便宜のために、ASP 接続アクセス用のコードをいくつか簡単にまとめます。古い環境と比較して、2 番目のコードを使用することをお勧めします。
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. win2003 以降のマシンの場合は、より効率的なこの方法を使用することをお勧めします。
set dbconnection=Server.CreateObject(ADODB.Connection)
DBPath = Server.MapPath(customer.mdb)
dbconnection.Open Provider=microsoft.jet.oldb.4.0;データ ソース=&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.oldb.4.0;データソース=&dbpath
SQL=select * from auth where id=' & user_id &'
session(rs).Open sql,connstr,1,3
4.
odbc ソース xxx をビルドする
set conn=server.createobject(Adodb.connection)
conn.open DSN=xxx;UID=;PWD=;データベース=顧客
5. SQLserver とアクセスによく使用されるデータベース接続コードが添付されています。
次のようにコードをコピーします。
<%
Const DataBaseType=1
DataBaseType=0 の場合、
DBPath=/jb51/news.asp
SqlNowString = Now()
ystr=true
nstr=false
スイジ=rnd(id)
それ以外
' SQL データベースの場合は、次のデータベース オプションを慎重に変更してください。
DataServer = wwwjb51net 'データベースサーバーIP
DataUser = jb51net 'アクセスデータベースのユーザー名
DataBaseName = jb51net 'データベース名
DataBasePsw = Password'アクセスデータベースパスワード
SqlNowString = getdate()
ystr=1
nstr=0
スイジ=newid()
次の場合に終了
エラー時は次へ再開
DataBaseType = 1 の場合
ConnStr=driver={SQL Server};server=&dataserver&;UID=&datauser&;PWD=&databasepsw&;Database=&databasename
それ以外
ConnStr = Provider=Microsoft.Jet.OLEDB.4.0;データ ソース= & Server.MapPath(DBPath)
終了の場合
conn = Server.CreateObject(ADODB.Connection) を設定します
conn.open ConnStr
Err then Err.Clear:Set conn = Nothing:Response.Write データベース接続エラーの場合は、Conn.asp ファイル内のデータベース パラメーター設定を確認してください。 :応答.終了
%>