다음을 통해 공유


DataSpace 개체 및 CreateObject 메서드 예제(VBScript)

중요

Windows 8 및 Windows Server 2012부터, RDS 서버 구성 요소는 더 이상 Windows 운영 체제에 포함되지 않습니다(자세한 내용은 Windows 8 및 Windows Server 2012 호환성 쿡북 참조). RDS 클라이언트 구성 요소는 이후 버전의 Windows에서 제거될 예정입니다. 새 개발 작업에서는 이 기능을 사용하지 않도록 하고, 현재 이 기능을 사용하는 애플리케이션은 수정하세요. RDS를 사용하는 애플리케이션은 WCF Data Service로 마이그레이션해야 합니다.

다음 예제는 기본 비즈니스 개체인 RDSServer.DataFactory와 함께 RDS.DataSpaceCreateObject 메서드를 사용하는 방법을 보여 줍니다. 이 예제를 테스트하려면 일반 HTML 문서에서 이 코드를 <Body> 태그와 </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의 인스턴스를 만드는 방법을 보여 줍니다. 또한 활성 서버 페이지 스크립팅을 사용하여 웹 서버 이름을 식별합니다.

전체 예제를 보려면 샘플 애플리케이션 선택기를 엽니다. Client Tier 열에서 VBScript in Internet Explorer를 선택합니다. Middle Tier 열에서 Custom Visual Basic Business Object를 선택합니다.

참고

Windows 인증을 지원하는 데이터 원본 공급자에 연결하는 경우 연결 문자열의 사용자 ID 및 암호 정보 대신 Trusted_Connection=yes 또는 Integrated Security=SSPI를 지정해야 합니다.

Sub Window_OnLoad()  
   strServer = "https://<%=Request.ServerVariables("SERVER_NAME")%>"  
   Set BO = ADS1.CreateObject("VbBusObj.VbBusObjCls", strServer)  
   txtConnect.Value = "dsn=Pubs;uid=MyUserID;pwd=MyPassword;"  
   txtGetRecordset.Value = "Select * From authors for Browse"  
End Sub  

참고 항목

CreateObject 메서드(RDS)
DataSpace 개체(RDS)