网页与数据库ACCESS怎么连接
发布网友
发布时间:2022-05-01 19:50
我来回答
共1个回答
热心网友
时间:2022-06-22 05:45
<%
'================================================================================================================
dim conn
dim connstr
dim db
db="admin/#data/%98data.mdb" '数据库文件位置
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
'On Error Resume Next
Set conn = Server.CreateObject("ADODB.Connection")
conn.commandtimeout=20
conn.open ConnStr
'If Err Then
'err.Clear
'Set Conn = Nothing
'Response.Write "<br><br><br><br><br><br><br><div align='center'>数据库连接出错!请检查连接数据库的参数及字符串设置是否正确!</div>"
'Response.End
'End If
'-----------------------------------------------------------------------------------------------------
'-----------------------------------------------------------------------------------------------------
'为了系统的安全,直接在有数据库连接的地方都加上SQL注入的免疫
'自定义需要过滤的字串,用 "|" 分隔
Fy_In = "'| ; | and | or | exec | insert | select | delete | update | count | * | % |chr(| char(| mid | master | truncate | declare "
'----------------------------------
Fy_Inf = split(Fy_In,"|")
If Request.QueryString<>"" Then
For Each Fy_Get In Request.QueryString
For Fy_Xh=0 To Ubound(Fy_Inf)
If Instr(LCase(Request.QueryString(Fy_Get)),Fy_Inf(Fy_Xh))<>0 Then
'--------写入数据库----------头-----
conn.Execute("insert into web_errlog(Sqlin_IP,SqlIn_Web,SqlIn_FS,SqlIn_CS,SqlIn_SJ) values('"&Request.ServerVariables("REMOTE_ADDR")&"','"&Request.ServerVariables("URL")&"','GET','"&Fy_Get&"','"&replace(Request.QueryString(Fy_Get),"'","''")&"')")
'--------写入数据库----------尾-----
response.redirect("/Error.html")
response.end
End If
Next
Next
End If