DataSpace 对象和 CreateObject 方法示例 (VBScript)
重要
从 Windows 8 和 Windows Server 2012 开始,RDS 服务器组件不再包含在 Windows 操作系统中(有关详细信息,请参阅 Windows 8 和 Windows Server 2012 兼容性指南)。 RDS 客户端组件将在将来的 Windows 版本中删除。 避免在新开发工作中使用此功能,并计划修改当前使用此功能的应用程序。 使用 RDS 的应用程序应迁移到 WCF 数据服务。
以下示例演示如何使用 RDS 的 CreateObject 方法。DataSpace 默认业务对象,RDSServer.DataFactory。 若要测试此示例,请将此代码剪切并粘贴到普通 HTML 文档中 <正文> 和 </Body> 标记之间,并将其命名为 DataSpaceVBS.asp。 ASP 脚本将标识服务器。
<!-- BeginDataSpaceVBS -->
<html>
<head>
<!--use the following META tag instead of adovbs.inc-->
<!--METADATA TYPE="typelib" uuid="00000205-0000-0010-8000-00AA006D2EA4" -->
<meta name="VI60_DefaultClientScript" content=VBScript>
<meta name="GENERATOR" content="Microsoft Visual Studio 6.0">
<title>DataSpace Object and CreateObject Method Example (VBScript)</title>
<style>
<!--
body {
font-family: 'Verdana','Arial','Helvetica',sans-serif;
BACKGROUND-COLOR:white;
COLOR:black;
}
.thead {
background-color: #008080;
font-family: 'Verdana','Arial','Helvetica',sans-serif;
font-size: x-small;
color: white;
}
.thead2 {
background-color: #800000;
font-family: 'Verdana','Arial','Helvetica',sans-serif;
font-size: x-small;
color: white;
}
.tbody {
text-align: center;
background-color: #f7efde;
font-family: 'Verdana','Arial','Helvetica',sans-serif;
font-size: x-small;
}
-->
</style>
</head>
<body>
<h1>DataSpace Object and CreateObject Method Example (VBScript)</h1>
<H2>RDS API Code Examples</H2>
<HR>
<H3>Using Query Method of RDSServer.DataFactory</H3>
<!-- RDS.DataSpace ID rdsDS-->
<OBJECT ID="rdsDS" WIDTH=1 HEIGHT=1
CLASSID="CLSID:BD96C556-65A3-11D0-983A-00C04FC29E36">
</OBJECT>
<!-- RDS.DataControl with parameters set at run time -->
<OBJECT classid="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33"
ID=RDS WIDTH=1 HEIGHT=1>
</OBJECT>
<TABLE DATASRC=#RDS>
<TBODY>
<TR>
<TD><SPAN DATAFLD="FirstName"></SPAN></TD>
<TD><SPAN DATAFLD="LastName"></SPAN></TD>
</TR>
</TBODY>
</TABLE>
<HR>
<INPUT TYPE=BUTTON NAME="Run" VALUE="Run">
<H4>Click Run -
The <i>CreateObject</i> Method of the RDS.DataSpace Object Creates an instance of the RDSServer.DataFactory.
The <i>Query</i> Method of the RDSServer.DataFactory is used to bring back a Recordset.</H4>
<Script Language="VBScript">
Dim rdsDF
Dim strServer
Dim strCnxn
Dim strSQL
strServer = "https://<%=Request.ServerVariables("SERVER_NAME")%>"
strCnxn = "Provider='sqloledb';Data Source=" & _
"<%=Request.ServerVariables("SERVER_NAME")%>" & ";" & _
"Integrated Security='SSPI';Initial Catalog='Northwind';"
strSQL = "Select FirstName, LastName from Employees"
Sub Run_OnClick()
Dim rs
' Create Data Factory
Set rdsDF = rdsDS.CreateObject("RDSServer.DataFactory", strServer)
'Get Recordset
Set rs = rdsDF.Query(strCnxn, strSQL)
' Use RDS.DataControl to bind Recordset to data-aware Table above
RDS.SourceRecordset = rs
End Sub
</Script>
</body>
</html>
<!-- EndDataSpaceVBS -->
以下示例演示如何使用 CreateObject 方法创建自定义业务对象的实例 VbBusObj.VbBusObjCls。 它还使用 Active Server Pages 脚本标识 Web 服务器名称。
若要查看完整示例,请打开示例应用程序选择器。 在 客户端层 列中,在 Internet Explorer 中选择VBScript。 在 中间层 列中,选择 自定义 Visual Basic Business 对象。
注意
如果要连接到支持 Windows 身份验证的数据源提供程序,则应指定 Trusted_Connection=yes 或 Integrated Security = SSPI,而不是连接字符串中的用户 ID 和密码信息。
Sub Window_OnLoad()
strServer = "https://<%=Request.ServerVariables("SERVER_NAME")%>"
Set BO = ADS1.CreateObject("VbBusObj.VbBusObjCls", strServer)
txtConnect.Value = "dsn=Pubs;uid=MyUserID;pwd=<password>;"
txtGetRecordset.Value = "Select * From authors for Browse"
End Sub