Esempio di metodo DataSpace e CreateObject (VBScript)
Importante
A partire da Windows 8 e Windows Server 2012, i componenti del server Servizi Desktop remoto non sono più inclusi nel sistema operativo Windows (vedere Windows 8 e Guida di riferimento per la compatibilità di Windows Server 2012 per altri dettagli). I componenti client di Servizi Desktop remoto verranno rimossi in una versione futura di Windows. Evitare di usare questa funzionalità nel nuovo lavoro di sviluppo e pianificare la modifica delle applicazioni che attualmente usano questa funzionalità. Le applicazioni che usano Servizi Desktop remoto devono eseguire la migrazione a WCF Data Service.
Nell'esempio seguente viene illustrato come usare il metodo CreateObject del RDS. DataSpace con l'oggetto business predefinito, RDSServer.DataFactory. Per testare questo esempio, tagliare e incollare questo codice tra <Body> e </Body> tag in un normale documento HTML e denominarlo DataSpaceVBS.asp. Lo script ASP identificherà il server.
<!-- 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 -->
Nell'esempio seguente viene illustrato come utilizzare il metodo CreateObject per creare un'istanza di un oggetto business personalizzato, VbBusObj.VbBusObjCls. Usa inoltre lo scripting pagine active server per identificare il nome del server Web.
Per visualizzare l'esempio completo, aprire il selettore di applicazioni di esempio. Nella colonna livello client selezionare VBScript in Internet Explorer. Nella colonna livello intermedio selezionare oggetto business di Visual Basic personalizzato.
Nota
Se ci si connette a un provider di origini dati che supporta l'autenticazione di Windows, è necessario specificare Trusted_Connection=yes o Integrated Security = SSPI anziché le informazioni sull'ID utente e sulla password nella stringa di connessione.
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