Package.SaveToXML(String, IDTSEvents) Méthode

Définition

Enregistre le package en mémoire dans un format XML. Pour enregistrer un package en tant que .xml sur le disque dur, utilisez la méthode 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)

Paramètres

packageXml
String

Paramètre out qui contient le code XML créé lors de l’enregistrement du package.

events
IDTSEvents

Objet qui implémente les événements en vue de déclencher des erreurs, des avertissements ou des messages d'information.

Exemples

L’exemple de code suivant crée un package et définit plusieurs propriétés de package. Le package est ensuite enregistré en mémoire XmlDocument à l’aide de la SaveToXML méthode. Ensuite, une nouvelle tâche est ajoutée au package. La tâche finale de l’exemple de code consiste à enregistrer l’intégralité du code XML dans un fichier sur le disque dur à l’aide SaveToXmlde .

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  

Remarques

Si vous souhaitez enregistrer un package en tant que fichier XML sur le disque dur, utilisez la Microsoft.SqlServer.Dts.Runtime.Application.SaveToXml méthode. Si vous souhaitez enregistrer le package dans le système de fichiers, utilisez Microsoft.SqlServer.Dts.Runtime.Application.SaveToDtsServer. Si vous souhaitez enregistrer le package dans la base de données MSDB, utilisez ou utilisez Microsoft.SqlServer.Dts.Runtime.Application.SaveToSqlServer des Microsoft.SqlServer.Dts.Runtime.Application.SaveToSqlServerAs méthodes. Lorsque vous appelez les Microsoft.SqlServer.Dts.Runtime.Application.SaveToXml méthodes sur le Applicationruntime, le runtime effectue une itération via les tâches, les gestionnaires de connexions, les fournisseurs de journaux et tous les autres objets contenus par le package et appellent la SaveToXML méthode sur chacun d’eux. Les objets contenus ont du code dans leur SaveToXML création d’un xmlElement pour chaque propriété que l’objet doit enregistrer et une valeur pour l’élément. Le package contient xmlDocument et les objets ajoutent leurs éléments spécifiques dans le XmlDocument du package. Par conséquent, vous n’appelez pas directement les SaveToXML objets individuels, mais appelez la méthode sur l’objet Application , et le runtime va cascader dans les objets de package et appeler pour SaveToXML vous.

S’applique à