上回曾贴一篇较简单的用ASP+RDS客户端参生报表
此回贴一篇较复杂的用ASP+RDS+组件客户端参生报表
错误说明:(若提示ActiveX 元件无法参生 RDS.DataSpace)
IE需设置安全选项
操作:菜单工具->INTERNET选项->安全性->自定义
设置:起始但ActiveX不标示为安全->开启
原理说明:
客户端直接用RDS产生RecordSet安全性不够,使用了
middle-tier Automation components 后可大大增加安全性!
请看下文:
编写注册元件:
ActiveX Dll project:iacrdsobj.vbp
Class Module name:RsOp
Public Function ReturnRs(strDB As Variant, strSQL As Variant) As ADODB.Recordset
'Returns an ADODB recordset.
On Error GoTo ehGetRecordset
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strConnect As String
strConnect = "Provider=SQLOLEDB;Server=server name ;uid=sa;pwd=; Database=" & strDB & ";"
cn.Open strConnect
'These are not listed in the typelib.
rs.CursorLocation = adUseClient
'Using the Unspecified parameters, an ADO/R recordset is returned.
rs.Open strSQL, cn, adOpenUnspecified, adLockUnspecified, adCmdUnspecified
Set ReturnRs = rs
Exit Function
ehGetRecordset:
Err.Raise Err.Number, Err.Source, Err.Description
End Function
然后 MAKE iacrdsobj.dll
若有错,请设置VB菜单PROJECT-REFREENCE
增加 MicroSoft ActiveX Data Object 2.6 Library(当然数字要高一点)
然后 注册iacrdsobj.dll到数据库server(为安全,最好更改数据库uid最好不为sa)!
好,接下来看asp
long1.asp
<html>
<head>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<title>client use rds produce excel report</title>
</head>
<body bgColor=skyblue topMargin=5 leftMargin="20" oncontextmenu="return false" rightMargin=0 bottomMargin="0">
<div align="center"><center>
<table border="1" bgcolor="#ffe4b5" style="HEIGHT: 1px; TOP: 0px" bordercolor="#0000ff">
<tr>
<td align="middle" bgcolor="#ffffff" bordercolor="#000080">
<font color="#000080" size="3">
client use rds produce excel report
</font>
</td>
</tr>
</table>
</div>
<form action="long1.asp" method="post" name="myform">
<DIV align=left>
<input type="button" value="Query Data" name="query" language="vbscript" onclick="fun_excel(1)" style="HEIGHT: 32px; WIDTH: 90px">
<input type="button" value="Clear Data" name="Clear" language="vbscript" onclick="fun_excel(2)" style="HEIGHT: 32px; WIDTH: 90px">
<input type="button" value="E