Ejemplo del objeto DataSpace y del método CreateObject (VBScript)
Importante
A partir de Windows 8 y Windows Server 2012, los componentes del servidor RDS ya no se incluyen en el sistema operativo Windows (consulte Windows 8 y Guía de compatibilidad de Windows Server 2012 para obtener más detalles). Los componentes de cliente de RDS se quitarán en una versión futura de Windows. Evite usar esta característica en el nuevo trabajo de desarrollo y planee modificar las aplicaciones que actualmente usan esta característica. Las aplicaciones que usan RDS deben migrar a servicio de datos WCF.
En el ejemplo siguiente se muestra cómo usar el método CreateObject del RDS de . DataSpace con el objeto de negocio predeterminado, RDSServer.DataFactory. Para probar este ejemplo, corte y pegue este código entre el> cuerpo de <y <las etiquetas /Body> en un documento HTML normal y asígnele el nombre DataSpaceVBS.asp. El script ASP identificará el servidor.
<!-- 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 -->
En el ejemplo siguiente se muestra cómo usar el método CreateObject para crear una instancia de un objeto de negocio personalizado, VbBusObj.VbBusObjCls. También usa el scripting active Server Pages para identificar el nombre del servidor web.
Para ver el ejemplo completo, abra el selector de aplicaciones de ejemplo. En la columna nivel de cliente de, seleccione VBScript en Internet Explorer. En la columna de nivel intermedio, seleccione Objeto empresarial personalizado de Visual Basic.
Nota
Si se conecta a un proveedor de origen de datos que admite la autenticación de Windows, debe especificar Trusted_Connection=sí o Integrated Security = SSPI en lugar del identificador de usuario y la información de contraseña en la cadena de conexión.
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