言語

Package.LoadFromXML(String, IDTSEvents) メソッド

定義

パッケージとそのメモリに保存されたすべてのオブジェクトをXML形式で読み込みます。 ハードドライブに保存されたパッケージを読み込むには、 LoadPackage(String, IDTSEvents) 方式を使います。

public:
 void LoadFromXML(System::String ^ packageXml, Microsoft::SqlServer::Dts::Runtime::IDTSEvents ^ events);
public void LoadFromXML(string packageXml, Microsoft.SqlServer.Dts.Runtime.IDTSEvents events);
override this.LoadFromXML : string * Microsoft.SqlServer.Dts.Runtime.IDTSEvents -> unit
Public Sub LoadFromXML (packageXml As String, events As IDTSEvents)

パラメーター

packageXml
String

パッケージをXML形式で含む文字列です。

events
IDTSEvents

永続性中にエラーや警告などのイベントを発生させるための IDTSEvents インターフェースを実装するオブジェクトです。

以下のコード例はパッケージを作成し、そこに2つのタスクを追加します。 パッケージXMLはメモリ内の XmlDocument に保存されます。 2つ目のパッケージが作成され、同じ XmlDocumentが読み込まれているため、最初のパッケージの重複となります。

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

namespace Microsoft.SqlServer.SSIS.Samples  
{  
    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);  

            // 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);  

            // Reload the package from its XML.  
            Package pkg2 = new Package();  
            pkg2.LoadFromXML(myPkgDocument, null);  
            Console.WriteLine("This is the package XML that pkg2 now contains:");  
            Console.Out.WriteLine(myPkgDocument.OuterXml);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text    
Imports Microsoft.SqlServer.Dts.Runtime  
Imports Microsoft.SqlServer.Dts.Tasks.BulkInsertTask  
Imports System.Xml  

Namespace Microsoft.SqlServer.SSIS.Samples  
    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)  

            ' 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, null);  

            ' Reload the package from its XML.  
            Dim pkg2 As Package =  New Package()   
            pkg2.LoadFromXML(myPkgDocument, Nothing)  
            Console.WriteLine("This is the package XML that pkg2 now contains:")  
            Console.Out.WriteLine(myPkgDocument.OuterXml)  
        End Sub  
    End Class  
End Namespace  

注釈

メモリ内のXMLを読み込むには LoadFromXML メソッドを使うべきです。 XMLとしてハードドライブに保存されたパッケージを読み込みたい場合は、 Microsoft.SqlServer.Dts.Runtime.Application.LoadPackage メソッドを使います。 パッケージがファイルシステムやMSDBデータベースに保存されている場合は、 Microsoft.SqlServer.Dts.Runtime.Application.LoadFromSqlServer または Microsoft.SqlServer.Dts.Runtime.Application.LoadFromDtsServer メソッドを使用します。

Application上のロードメソッドを呼び出すと、ランタイムはパッケージに含まれるタスク、接続マネージャー、ログプロバイダー、その他すべてのオブジェクトを順次処理し、それぞれのLoadFromXMLメソッドを呼び出します。 含まれるオブジェクトのコードは、オブジェクトが再作成しなければならない各プロパティのXmlElementと、その要素のために保存された値を解析するコード LoadFromXML に含まれています。 したがって、個々のオブジェクトの LoadFromXML を直接呼び出すのではなく、 Application オブジェクトのメソッドを呼び出すと、ランタイムがパッケージ全体にカスケードされ、オブジェクトの LoadFromXML を呼び出します。

適用対象