Package.SaveToXML(String, IDTSEvents) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
以 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
一个对象,该对象实现事件以引发错误、警告或信息性事件。
示例
下面的代码示例创建一个包并设置多个包属性。 然后,使用SaveToXML该方法将包保存到内存XmlDocument
中。 接下来,将新任务添加到包中。 The final task of the code example is to save the entire XML to a file on the hard-drive using 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.SaveToSqlServer 或 Microsoft.SqlServer.Dts.Runtime.Application.SaveToSqlServerAs 方法。 调用 Microsoft.SqlServer.Dts.Runtime.Application.SaveToXml 方法 Application时,运行时将循环访问包包含的任务、连接管理器、日志提供程序和其他所有对象,并在其中每个对象上调用 SaveToXML
该方法。 包含的对象在其中包含 SaveToXML
代码,该代码为对象必须保存的每个属性创建 XmlElement,以及元素的值。 该包包含 XmlDocument,对象将其特定元素追加到包的 XmlDocument 中。 因此,您不直接调用 SaveToXML
单个对象,而是对对象调用该方法 Application ,运行时将通过包对象级联并调用 SaveToXML
该对象。