asp连接数据库代码实例

时间:2022-11-23 10:51:52 作者:壹号 字数:1548字

asp 连接数据库代码实例

连接数据库代码实例

1,连接数据库代码 文件名称 conn.asp 所有访问数据库的文件都调用此文件<!--#include file="Conn.asp"-->

<%

db="data/data.mdb" '数据库存放目录

on error resume next

set conn=server.createobject("adodb.connection")

conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath(db) if err then

err.clear

set conn = Nothing

response.write "数据库连接出错,请检查conn.asp中的连接字符串。" response.end

end if

function CloseDB

Conn.Close

set Conn=Nothing

End Function

%>

<%

dim badword

badword="'|and|select|update|chr|delete|%20from|;|insert|mid|master.|set|chr(37)|="

if request.QueryString<>"" then

chk=split(badword,"|")

for each query_name in request.querystring

for i=0 to ubound(chk)

if instr(lcase(request.querystring(query_name)),chk(i))<>0 then

response.write "<script language=javascript>alert('传参错误!参数 "&query_name&" 的值中包含非法字符串!\n\n');location='"&request.ServerVariables("HTTP_REFERER")&"'</Script>" response.end

…… 此处隐藏0字 ……

end if

next

next

end if

%>

----------------------------------------------