Application.SaveToSqlServer 方法

定义

将包保存到 SQL Server 实例。

public:
 void SaveToSqlServer(Microsoft::SqlServer::Dts::Runtime::Package ^ package, Microsoft::SqlServer::Dts::Runtime::IDTSEvents ^ events, System::String ^ serverName, System::String ^ serverUserName, System::String ^ serverPassword);
public void SaveToSqlServer (Microsoft.SqlServer.Dts.Runtime.Package package, Microsoft.SqlServer.Dts.Runtime.IDTSEvents events, string serverName, string serverUserName, string serverPassword);
member this.SaveToSqlServer : Microsoft.SqlServer.Dts.Runtime.Package * Microsoft.SqlServer.Dts.Runtime.IDTSEvents * string * string * string -> unit
Public Sub SaveToSqlServer (package As Package, events As IDTSEvents, serverName As String, serverUserName As String, serverPassword As String)

参数

package
Package

要保存的包。

events
IDTSEvents

IDTSEvents 对象。

serverName
String

要将包保存到的 SQL Server 实例的名称。

serverUserName
String

用于登录到服务器的用户名。

serverPassword
String

用户帐户的密码。

示例

下面的代码示例将示例包保存到SQL Server。 若要验证包是否已保存,请对 msdb 数据库运行以下 Transact-SQL 查询。 查询返回存储在 msdb 系统表中的所有包。

select * from sysssispackages

或者,连接到 Integration Services 服务,展开 存储的包,然后展开 MSDB。 将列出名为 UsingExecuteProcess 的包。

using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  

namespace LoadFromSQLServerTest  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            // The variable, pkg, points to the location  
            // of the UsingExecuteProcess sample installed with  
            // the SSIS package samples.  
            string pkg = @"C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx";  
            Application app = new Application();  
            Package loadedPkg = app.LoadPackage(pkg, null);  

            // Save the package to SQL Server.  
            app.SaveToSqlServer(loadedPkg, null, "yourserver", null, null);  

            // The package can now be viewed in the   
            // Microsoft SQL Server Management Studio, in the   
            // Integration Services / Stored Packages / MSDB folder,  
            // with the name UsingExecuteProcess.  
            Package pkgIn = new Package();  
            pkgIn = app.LoadFromSqlServer("\\UsingExecuteProcess", "yourserver", null, null, null);  
            DateTime pkgCreation = pkgIn.CreationDate;  
            Console.WriteLine("Creation Date = {0}", pkgCreation);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace LoadFromSQLServerTest  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            ' The variable, pkg, points to the location  
            ' of the UsingExecuteProcess sample installed with  
            ' the SSIS package samples.  
            Dim pkg As String =  "C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx"   
            Dim app As Application =  New Application()   
            Dim loadedPkg As Package =  app.LoadPackage(pkg,Nothing)   

            ' Save the package to SQL Server.  
            app.SaveToSqlServer(loadedPkg, Nothing, "yourserver", Nothing, Nothing)  

            ' The package can now be viewed in the   
            ' Microsoft SQL Server Management Studio, in the   
            ' Integration Services / Stored Packages / MSDB folder,  
            ' with the name UsingExecuteProcess.  
            Dim pkgIn As Package =  New Package()   
            pkgIn = app.LoadFromSqlServer("\\UsingExecuteProcess", "yourserver", Nothing, Nothing, Nothing)  
            Dim pkgCreation As DateTime =  pkgIn.CreationDate   
            Console.WriteLine("Creation Date = {0}", pkgCreation)  
        End Sub  
    End Class  
End Namespace  

示例输出:

Creation Date = 5/5/2003 5:46:00 PM

适用于