Package.SaveToXML(String, IDTSEvents) Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Guarda el paquete en memoria en un formato XML. Para guardar un paquete como .xml en el disco duro, utilice el método 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)
Parámetros
- packageXml
- String
Parámetro out que contiene el XML que se crea cuando se guarda el paquete.
- events
- IDTSEvents
Un objeto que implementa los eventos para generar errores, advertencias o eventos informativos.
Ejemplos
En el ejemplo de código siguiente se crea un paquete y se establecen varias propiedades de paquete. A continuación, el paquete se guarda en una memoria XmlDocument
mediante el SaveToXML método . A continuación, se agrega una nueva tarea al paquete. La tarea final del ejemplo de código es guardar todo el XML en un archivo en el disco duro mediante 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
Comentarios
Si desea guardar un paquete como XML en el disco duro, use el Microsoft.SqlServer.Dts.Runtime.Application.SaveToXml método . Si desea guardar el paquete en el sistema de archivos, use Microsoft.SqlServer.Dts.Runtime.Application.SaveToDtsServer. Si desea guardar el paquete en la base de datos MSDB, use Microsoft.SqlServer.Dts.Runtime.Application.SaveToSqlServer los métodos o Microsoft.SqlServer.Dts.Runtime.Application.SaveToSqlServerAs . Al llamar a los Microsoft.SqlServer.Dts.Runtime.Application.SaveToXml métodos en Application, el tiempo de ejecución recorrerá en iteración las tareas, los administradores de conexiones, los proveedores de registro y todos los demás objetos que contiene el paquete y llamarán al SaveToXML
método en cada uno de ellos. Los objetos contenidos tienen código en su que SaveToXML
crea un XmlElement para cada propiedad que el objeto debe guardar y un valor para el elemento. El paquete contiene XmlDocument y los objetos anexan sus elementos específicos a XmlDocument del paquete. Por lo tanto, no llama directamente a SaveToXML
en los objetos individuales, sino que llama al método en el Application objeto y el tiempo de ejecución se en cascada a través de los objetos del paquete y llama a SaveToXML
para usted.