Advertisement
paulogp

SSIS: Correr um SSIS a partir de um Script Task (v 1.0.0)

Jul 13th, 2011
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. /* Exemplo de como chamar um SSIS e enviar valores usando o componente Script Task */
  2.  
  3.  
  4. using System;
  5. using System.Data;
  6. using Microsoft.SqlServer.Dts.Runtime;
  7.  
  8. namespace ST_c82cf79963ff44c7bae239e77704543a.csproj {
  9.     [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
  10.     public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase {
  11.  
  12.         #region VSTA generated code
  13.         enum ScriptResults
  14.         {
  15.             Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
  16.             Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
  17.         };
  18.         #endregion
  19.  
  20.  
  21.         // USER CODE
  22.         // WARNING: VARS ON Package1.dtsx
  23.         // global vars: ssis_variable; String or Object
  24.         // box: readWriteVariable: User::ssis_variable
  25.         public void Main() {
  26.             Application the_app = new Application();
  27.  
  28.             //
  29.             // load package from file system
  30.             string the_path = "D:\\services_2011\\indicadores_gerais\\indicadores_gerais\\Package1.dtsx";
  31.  
  32.             Package the_package = the_app.LoadPackage(the_path, null);
  33.             //the_package.ImportConfigurationFile("c:\\ExamplePackage.dtsConfig");
  34.  
  35.             // vars from the calling package
  36.             Variables vars = the_package.Variables;
  37.             vars["User::ssis_variable"].Value = "value from c#";
  38.  
  39.             // get result
  40.             DTSExecResult the_result = the_package.Execute();
  41.  
  42.             // write result to console
  43.             Console.WriteLine("Package Execution results: {0}", the_result.ToString());
  44.  
  45.  
  46.             //
  47.             // load package from SQL Server
  48.             Package the_package_2 = the_app.LoadFromSqlServer("ExamplePackage", "server_name", "sa", "your_password", null);
  49.  
  50.             //the_package_2.ImportConfigurationFile("c:\\ExamplePackage.dtsConfig");
  51.  
  52.             DTSExecResult the_result_2 = the_package_2.Execute();
  53.             Console.WriteLine("Package Execution results: {0}", the_result_2.ToString());
  54.  
  55.  
  56.             // TODO: Add your code here
  57.             Dts.TaskResult = (int)ScriptResults.Success;
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement