2016-10-04 11 views
0

3つの接続マネージャー(プロジェクトレベルで定義されています)を使用して統合サービスプロジェクトを作成しました。これでSSISパッケージ(.dtsxファイル)が作成されました。私のアプリで。 だから私は以下のようにMicrosoft.SqlServer.Dts名前空間を使用します。SSISパッケージとその接続マネージャーをWPFアプリケーションにロード

string pkgLocation; 
Package pkg; 
Microsoft.SqlServer.Dts.Runtime.Application app; 
DTSExecResult pkgResults; 
pkgLocation = @"D:\My Job\Tadbirgaran\Integration Services Project\MyPackage.dtsx"; 
app = new Microsoft.SqlServer.Dts.Runtime.Application(); 
pkg = app.LoadPackage(pkgLocation, null); 
pkgResults = pkg.Execute(); 

が、このコードは、私はプログラムで接続マネージャのファイルをロードし、パッケージに追加することができますどのような方法があり、明らかにプロジェクトの接続マネージャをロードしません。接続プロパティ?統合サービスプロジェクトで自分のパッケージに接続を定義する必要がありますか?

答えて

0

私の代わりに、パッケージのプロジェクトをロードすると、以下のようにパッケージ化するプロジェクトからの接続を設定することになった:

 private void SSISLoadData() 
     { 
      Project ssisProject = null; 
      DTSExecResult pkgResults; 
      try 
      { 
       ssisProject = Project.OpenProject(@"D:\My Job\TDB\Integration Services Project\bin\Development\Integration Services Project.ispac"); 
       Package pkg = ssisProject.PackageItems[0].LoadPackage(null); 
       for (int i = 0; i < ssisProject.ConnectionManagerItems.Count; i++) 
        pkg.Connections.Join(ssisProject.ConnectionManagerItems[i].ConnectionManager); 
       pkg.Connections[0].ConnectionString = dataFolderPath + "\\*.csv"; 
       pkg.Connections[1].ConnectionString = string.Format("Data Source =.; Initial Catalog = TDB; Provider = SQLNCLI11.1; Integrated Security = SSPI; Initial File Name = {0};", dbPath); 
       pkg.Connections[2].ConnectionString = string.Format("Data Source =.; Initial Catalog = TDBRawData; Provider = SQLNCLI11.1; Integrated Security = SSPI; Initial File Name = {0}\\TDBRawData.mdf;", Environment.CurrentDirectory); 
       pkgResults = pkg.Execute(); 
       MessageBox.Show(pkgResults.ToString()); 
      } 
      catch (Exception e) 
      { 
       MessageBox.Show(e.Message); 
      } 
      finally 
      { 
       if (ssisProject != null) 
        ssisProject.Dispose(); 
      } 
     } 

私はこの問題のより良い解決策がある場合は知っているが、それはありません働く

0

構成を使用して、プログラムによって接続プロパティを制御できます。ここに例があります。

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

namespace configuration_API 
{ 
    class Program 
    {  
     static void Main(string[] args) 
     { 
     // Create a package and set two properties. 
      Package pkg = new Package(); 
      pkg.EnableConfigurations = true; 
      pkg.ExportConfigurationFile(@"C:\conf.xml"); 

      // Create a variable object and add it to the 
      // package Variables collection. 
      Variable varPkg = pkg.Variables.Add("var", false, "", 100); 
      varPkg.Value = 1; 
      string packagePathToVariable = varPkg.GetPackagePath(); 

      // Create a configuration object and add it to the 
      // package configuration collection. 
      Configuration config = pkg.Configurations.Add(); 

      // Set properties on the configuration object. 
      config.ConfigurationString = "conf.xml"; 
      config.Description = "My configuration description"; 
      config.ConfigurationType = DTSConfigurationType.ConfigFile; 
      config.PackagePath = packagePathToVariable; 

      // Save the package and its configuration. 
      Application app = new Application(); 
      app.SaveToXml(@"c:\pkg.xml", pkg, null); 

      // Reload the package. 
      Package p1 = app.LoadPackage(@"c:\pkg.xml", null); 
      // Review the configuration information. 
      Configurations configs_After = pkg.Configurations; 
      foreach(Configuration confAfter in configs_After) 
      { 
       Console.WriteLine("ConfigurationString is {0}", confAfter.ConfigurationString); 
       Console.WriteLine("ConfigurationType is {0}", confAfter.ConfigurationType); 
       Console.WriteLine("CreationName is {0}", confAfter.CreationName); 
       Console.WriteLine("Description is {0}", confAfter.Description); 
       Console.WriteLine("Assigned ID is {0}", confAfter.ID); 
       Console.WriteLine("Name is {0}", confAfter.Name); 
      } 
     } 
    } 
} 
関連する問題