Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.79 KB | None | 0 0
  1. #region Help:  Introduction to the script task
  2. /* The Script Task allows you to perform virtually any operation that can be accomplished in
  3.  * a .Net application within the context of an Integration Services control flow.
  4.  *
  5.  * Expand the other regions which have "Help" prefixes for examples of specific ways to use
  6.  * Integration Services features within this script task. */
  7. #endregion
  8.  
  9.  
  10. #region Namespaces
  11. using System;
  12. using System.Data;
  13. using System.Net; // MUST ADD
  14. using System.Net.Mail; // MUST ADD
  15. using Microsoft.SqlServer.Dts.Runtime;
  16. using System.Windows.Forms;
  17. #endregion
  18.  
  19. namespace ST_b4d724ba74264c9c8b4a3486de483c0c
  20. {
  21.     /// <summary>
  22.     /// ScriptMain is the entry point class of the script.  Do not change the name, attributes,
  23.     /// or parent of this class.
  24.     /// </summary>
  25.     [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
  26.     public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
  27.     {
  28.         #region Help:  Using Integration Services variables and parameters in a script
  29.         /* To use a variable in this script, first ensure that the variable has been added to
  30.          * either the list contained in the ReadOnlyVariables property or the list contained in
  31.          * the ReadWriteVariables property of this script task, according to whether or not your
  32.          * code needs to write to the variable.  To add the variable, save this script, close this instance of
  33.          * Visual Studio, and update the ReadOnlyVariables and
  34.          * ReadWriteVariables properties in the Script Transformation Editor window.
  35.          * To use a parameter in this script, follow the same steps. Parameters are always read-only.
  36.          *
  37.          * Example of reading from a variable:
  38.          *  DateTime startTime = (DateTime) Dts.Variables["System::StartTime"].Value;
  39.          *
  40.          * Example of writing to a variable:
  41.          *  Dts.Variables["User::myStringVariable"].Value = "new value";
  42.          *
  43.          * Example of reading from a package parameter:
  44.          *  int batchId = (int) Dts.Variables["$Package::batchId"].Value;
  45.          *  
  46.          * Example of reading from a project parameter:
  47.          *  int batchId = (int) Dts.Variables["$Project::batchId"].Value;
  48.          *
  49.          * Example of reading from a sensitive project parameter:
  50.          *  int batchId = (int) Dts.Variables["$Project::batchId"].GetSensitiveValue();
  51.          * */
  52.  
  53.         #endregion
  54.  
  55.         #region Help:  Firing Integration Services events from a script
  56.         /* This script task can fire events for logging purposes.
  57.          *
  58.          * Example of firing an error event:
  59.          *  Dts.Events.FireError(18, "Process Values", "Bad value", "", 0);
  60.          *
  61.          * Example of firing an information event:
  62.          *  Dts.Events.FireInformation(3, "Process Values", "Processing has started", "", 0, ref fireAgain)
  63.          *
  64.          * Example of firing a warning event:
  65.          *  Dts.Events.FireWarning(14, "Process Values", "No values received for input", "", 0);
  66.          * */
  67.         #endregion
  68.  
  69.         #region Help:  Using Integration Services connection managers in a script
  70.         /* Some types of connection managers can be used in this script task.  See the topic
  71.          * "Working with Connection Managers Programatically" for details.
  72.          *
  73.          * Example of using an ADO.Net connection manager:
  74.          *  object rawConnection = Dts.Connections["Sales DB"].AcquireConnection(Dts.Transaction);
  75.          *  SqlConnection myADONETConnection = (SqlConnection)rawConnection;
  76.          *  //Use the connection in some code here, then release the connection
  77.          *  Dts.Connections["Sales DB"].ReleaseConnection(rawConnection);
  78.          *
  79.          * Example of using a File connection manager
  80.          *  object rawConnection = Dts.Connections["Prices.zip"].AcquireConnection(Dts.Transaction);
  81.          *  string filePath = (string)rawConnection;
  82.          *  //Use the connection in some code here, then release the connection
  83.          *  Dts.Connections["Prices.zip"].ReleaseConnection(rawConnection);
  84.          * */
  85.         #endregion
  86.  
  87.  
  88.         /// <summary>
  89.         /// This method is called when this script task executes in the control flow.
  90.         /// Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
  91.         /// To open Help, press F1.
  92.         /// </summary>
  93.         public void Main()
  94.         {
  95.             var username = "apikey";
  96.             var password = "<insert your SendGrid API Key here>";
  97.  
  98.             string to = "someone@company.local";
  99.             string from = "noreply@company.local";
  100.             MailMessage message = new MailMessage(from, to)
  101.             {
  102.                 IsBodyHtml = false,
  103.                 Subject = "From SSIS via SendGrid using the SMTP client.",
  104.                 Body = @"Using this new feature, you can send an email message from an application very easily."
  105.             };
  106.             SmtpClient client = new SmtpClient("smtp.sendgrid.net", 587);
  107.             client.UseDefaultCredentials = false;
  108.             client.Credentials = new NetworkCredential(username, password);
  109.             client.Send(message);
  110.  
  111.             Dts.TaskResult = (int)ScriptResults.Success;
  112.         }
  113.  
  114.         #region ScriptResults declaration
  115.         /// <summary>
  116.         /// This enum provides a convenient shorthand within the scope of this class for setting the
  117.         /// result of the script.
  118.         ///
  119.         /// This code was generated automatically.
  120.         /// </summary>
  121.         enum ScriptResults
  122.         {
  123.             Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
  124.             Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
  125.         };
  126.         #endregion
  127.  
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement