Package.SaveToXML(String, IDTSEvents) 메서드

정의

패키지를 메모리에 XML 형식으로 저장합니다. 패키지를 하드 드라이브에 .xml로 저장하려면 SaveToXml(String, Package, IDTSEvents) 메서드를 사용합니다.

public:
 void SaveToXML([Runtime::InteropServices::Out] System::String ^ % packageXml, Microsoft::SqlServer::Dts::Runtime::IDTSEvents ^ events);
public void SaveToXML (out string packageXml, Microsoft.SqlServer.Dts.Runtime.IDTSEvents events);
override this.SaveToXML : string * Microsoft.SqlServer.Dts.Runtime.IDTSEvents -> unit
Public Sub SaveToXML (ByRef packageXml As String, events As IDTSEvents)

매개 변수

packageXml
String

패키지를 저장할 때 생성되는 XML을 포함하는 out 매개 변수입니다.

events
IDTSEvents

오류, 경고 또는 정보 이벤트를 발생시키는 이벤트를 구현하는 개체입니다.

예제

다음 코드 예제에서는 패키지를 만들고 여러 패키지 속성을 설정합니다. 그런 다음, 메서드를 사용하여 패키지가 메모리 XmlDocument 내로 저장됩니다 SaveToXML . 다음으로 새 작업이 패키지에 추가됩니다. 코드 예제의 마지막 작업은 전체 XML을 사용하여 하드 드라이브 SaveToXml의 파일에 저장하는 것입니다.

using System;  
using System.Collections.Generic;  
using System.Text;    
using Microsoft.SqlServer.Dts.Runtime;  
using Microsoft.SqlServer.Dts.Tasks.BulkInsertTask;  
using System.Xml;  

namespace SaveToXML_API  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Application app = new Application();  

            // Location and file name can be combined into one string,  
            // or location could be set by a variable instead of hard-coded.  
            String XmlLocation = @"C:\XML";  
            String XmlFileName = "TestXML.xml";  
            String XmlFile = XmlLocation + XmlFileName;  
            Package pkg = new Package();  
            pkg.CreatorName = "Test";  
            pkg.Name = "SaveToXML Package";  
            pkg.CheckSignatureOnLoad = true;  
            pkg.DelayValidation = false;  
            pkg.SaveCheckpoints = false;  

            // Create package XmlDocument and use in pkg.SaveToXml.  
            XmlDocument myPkgDocument = new XmlDocument();  
            pkg.SaveToXML(ref myPkgDocument, null, null);  
            // If you want to see what the package XML contains   
            // at this point, uncomment this line and view the console.  
            // Console.Out.WriteLine(myPkgDocument.OuterXml);  

            // Now modify the package. Create a task   
            // and set some properties.  
            Executable execBI = pkg.Executables.Add("STOCK:BulkInsertTask");  
            TaskHost th = execBI as TaskHost;  
            th.Properties["DebugMode"].SetValue(th, false);  
            // You can cast the task here.  
            // BulkInsertTask myTask = th.InnerObject as BulkInsertTask;  

            // Save the task into the package using pkg.SaveToXML.  
            // This saves the package after it has been modified  
            // by the addition of the task.  
            pkg.SaveToXML(ref myPkgDocument, null, null);  

            // When you want to save the package to the hard-drive,  
            // Save using the Application.SaveToXML method.  
            app.SaveToXml(XmlFile, pkg, null);  

        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text    
Imports Microsoft.SqlServer.Dts.Runtime  
Imports Microsoft.SqlServer.Dts.Tasks.BulkInsertTask  
Imports System.Xml  

Namespace SaveToXML_API  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim app As Application =  New Application()   

            ' Location and file name can be combined into one string,  
            ' or location could be set by a variable instead of hard-coded.  
            Dim XmlLocation As String =  "C:\XML"   
            Dim XmlFileName As String =  "TestXML.xml"   
            Dim XmlFile As String =  XmlLocation + XmlFileName   
            Dim pkg As Package =  New Package()   
            pkg.CreatorName = "Test"  
            pkg.Name = "SaveToXML Package"  
            pkg.CheckSignatureOnLoad = True  
            pkg.DelayValidation = False  
            pkg.SaveCheckpoints = False  

            ' Create package XmlDocument and use in pkg.SaveToXml.  
            Dim myPkgDocument As XmlDocument =  New XmlDocument()   
            pkg.SaveToXML( myPkgDocument,Nothing,Nothing)  
            ' If you want to see what the package XML contains   
            ' at this point, uncomment this line and view the console.  
            ' Console.Out.WriteLine(myPkgDocument.OuterXml);  

            ' Now modify the package. Create a task   
            ' and set some properties.  
            Dim execBI As Executable =  pkg.Executables.Add("STOCK:BulkInsertTask")   
            Dim th As TaskHost =  execBI as TaskHost   
            th.Properties("DebugMode").SetValue(th, False)  
            ' You can cast the task here.  
            ' BulkInsertTask myTask = th.InnerObject as BulkInsertTask;  

            ' Save the task into the package using pkg.SaveToXML.  
            ' This saves the package after it has been modified  
            ' by the addition of the task.  
            pkg.SaveToXML( myPkgDocument,Nothing,Nothing)  

            ' When you want to save the package to the hard-drive,  
            ' Save using the Application.SaveToXML method.  
            app.SaveToXml(XmlFile, pkg, Nothing)  

        End Sub  
    End Class  
End Namespace  

설명

패키지를 하드 드라이브에 XML로 저장하려면 이 메서드를 Microsoft.SqlServer.Dts.Runtime.Application.SaveToXml 사용합니다. 패키지를 파일 시스템에 저장하려면 다음을 사용합니다 Microsoft.SqlServer.Dts.Runtime.Application.SaveToDtsServer. 패키지를 MSDB 데이터베이스에 저장하려면 사용하거나 Microsoft.SqlServer.Dts.Runtime.Application.SaveToSqlServerAs 메서드를 사용합니다Microsoft.SqlServer.Dts.Runtime.Application.SaveToSqlServer. 메서드를 Microsoft.SqlServer.Dts.Runtime.Application.SaveToXmlApplication호출할 때 런타임은 태스크, 연결 관리자, 로그 공급자 및 패키지에 포함된 다른 모든 개체를 반복하고 각 개체에 대해 메서드를 SaveToXML 호출합니다. 포함된 개체에는 개체가 SaveToXML 저장해야 하는 각 속성에 대한 XmlElement와 요소의 값을 만드는 코드가 있습니다. 패키지에는 XmlDocument가 포함되고 개체는 해당 특정 요소를 패키지의 XmlDocument에 추가합니다. 따라서 개별 개체에서 직접 호출 SaveToXML 하지 않고 개체에서 Application 메서드를 호출하면 런타임이 패키지 개체를 통해 계단식으로 이동하고 해당 개체를 SaveToXML 호출합니다.

적용 대상