Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8363373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:09:38+00:00 2026-06-09T12:09:38+00:00

Purpose: Fetch all the user variables that are in the SSIS package and write

  • 0

Purpose: Fetch all the user variables that are in the SSIS package and write the variable name and their values in a SQL Server 2008 table.

What have I tried: I got a small “Script Task” working to Display the variable name and their value. The script is as follows.

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
namespace ST_81ec2398155247148a7dad513f3be99d.csproj
{
    [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {

        #region VSTA generated code
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion

    public void Main()
    {


        Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
        Package pkg = app.LoadPackage(
          @"C:\package.dtsx",
          null);
        Variables pkgVars = pkg.Variables;

        foreach (Variable pkgVar in pkgVars)
        {
            if (pkgVar.Namespace.ToString() == "User")
            {
                MessageBox.Show(pkgVar.Name);
                MessageBox.Show(pkgVar.Value.ToString());
            }
        }
        Console.Read();
    }
    }

    }

What needs to be done: I need to take this and dump the values to a database table. I am trying to work on a script component for this, but due to lack of knowledge of .net scripting, I havent gotten anywhere close to the finish line. This is what I have done on the component side.

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using Microsoft.SqlServer.Dts;
using System.Windows.Forms;

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{

   public override void CreateNewOutputRows()
    {

        #region Class Variables
        IDTSVariables100 variables;
        #endregion

        variables = null;

        this.VariableDispenser.GetVariables(out variables);
        foreach(Variable myVar in variables)
        {
            MessageBox.Show(myVar.Value.ToString());
            if (myVar.Namespace == "User")
            {
                Output0Buffer.ColumnName = myVar.Value.ToString();
            }
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:09:39+00:00Added an answer on June 9, 2026 at 12:09 pm

    I can think of 2 ways of solving this issue right now .

    1. Use the same script task to insert the values into the Database
    2. using Foreach loop to enumerate the ssis package variables ( as you have asked )

    Table Script for inserting the variable name and value is

    CREATE TABLE [dbo].[SSISVariables]
    (
    [Name] [varchar](50) NULL,
    [Value] [varchar](50) NULL
    )
    

    1.Use Script task and write the below code

    [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {
        private static string m_connectionString = @"Data Source=Server Name;
        Initial Catalog=Practice;Integrated Security=True";
       public void Main()
        {
           List<SSISVariable> _coll = new List<SSISVariable>();
            Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
            Package pkg = app.LoadPackage(PackageLocation,Null);
                       Variables pkgVars = pkg.Variables;
    
            foreach (Variable pkgVar in pkgVars)
            {
                if (pkgVar.Namespace.ToString() == "User")
                {
                    _coll.Add(new SSISVariable ()
                    {
                     Name =pkgVar.Name.ToString(),
                     Val =pkgVar .Value.ToString () 
                    });
               }
            }
            InsertIntoTable(_coll);
            Dts.TaskResult = (int)ScriptResults.Success;
        }
    
        public void InsertIntoTable(List<SSISVariable> _collDetails)
        {  
           using (SqlConnection conn = new SqlConnection(m_connectionString))
            {
                conn.Open();
                foreach (var item in _collDetails )
                {
                 SqlCommand command = new SqlCommand("Insert into SSISVariables values (@name,@value)", conn);
                 command.Parameters.Add("@name", SqlDbType.VarChar).Value = item.Name ;
    
                 command.Parameters.Add("@value", SqlDbType.VarChar).Value = item.Val ;
                 command.ExecuteNonQuery();    
                }
            }
         }
      }
    
       public class SSISVariable
       {
        public string Name { get; set; }
        public string Val { get; set; }
       }
    

    Explanation:In this ,i’m creating a class which has properties Name and Val . Retrieve the package variables and their value using your code and store them in a collection List<SSISVariable> .Then pass this collection to a method (InsertIntoTable) which simply inserts the value into the database by enumerating through the collection .

    Note :

    There is a performance issue with the above code ,as for every variable 
    im hitting the database and inserting the value.You can use
    [TVP][1]( SQL Server 2008)   or stored procedure which takes
     xml( sql server 2005) as input. 
    

    2.Using ForEach Loop

    Design

    enter image description here

    Step 1: create a Variable VariableCollection which is of type System.Object and another
    variable Item which is of type String to store the result from Foreach loop

    Step 2: For the 1st script task .

    VariableCollection is used to store the Variable name and its value
    enter image description here

    Step 3: Inside the script task Main Method write the following code

      public void Main()
       {
         ArrayList _coll = new ArrayList(); 
    
            Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
            Package pkg = app.LoadPackage(Your Package Location,null);
    
            Variables pkgVars = pkg.Variables;
            foreach (Variable pkgVar in pkgVars)
            {
                if (pkgVar.Namespace.ToString() == "User")
                {
                    _coll.Add(string.Concat ( pkgVar.Name,',',pkgVar.Value ));
                }
            }
            Dts.Variables["User::VariableCollection"].Value = _coll;
            // TODO: Add your code here
            Dts.TaskResult = (int)ScriptResults.Success;
        }
    

    Step 4: Drag a Foreach loop and in the expression use Foreach from Variable Enumerator

    enter image description here

    Step 5:Foreach loop enumerates the value and stores it in a variable User::Item

    enter image description here

    Step 6:Inside the foreach loop drag a script task and select the variable

    readonly variables   User::Item 
    

    step 7: Write the below code in the main method

       public void Main()
        {
          string name = string.Empty;
          string[] variableCollection;
          variableCollection = Dts.Variables["User::Item"].Value.ToString().Split(',');
          using (SqlConnection conn = new SqlConnection(m_connectionString))
            {
                conn.Open();
                SqlCommand command = new SqlCommand("Insert into SSISVariables values (@name,@value)", conn);
                command.Parameters.Add("@name", SqlDbType.VarChar).Value = variableCollection[0];
    
                command.Parameters.Add("@value", SqlDbType.VarChar).Value = variableCollection[1];
    
                command.ExecuteNonQuery();
            }
            // TODO: Add your code here
            Dts.TaskResult = (int)ScriptResults.Success;
        }
    

    Explanation : In the Foreach loop ,i can only enumerate one variable .So the logic is, i need to somehow pass the variable name and its value into one variable .And for this ,i have concatenated name and value

     string.Concat ( pkgVar.Name,',',pkgVar.Value )
    

    Script task in the foreach loop simply splits the variable and stores it into a array of string and then u can access the name and value using array index and store it in the database

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for testing purpose I wrote a VBscript which will fetch values from Sybase by
I'm wanting to fetch all the values of the Category column of a table
The purpose I aming for is, that 2 seconds after my activity was started
My purpose is user enter only email or mobile number. I have the partial
The purpose of this code is to pull upgrade.zip from a central server, extract
Short During debug process I see that, all goes right. For debugging purposes, before
I have my own db class which has some purpose built functions that I
I have the following PL/SQL being sent to a remote oracle 11gr2 server via
I have to store messages that my web app fetch from Twitter into a
I have a pointer to a structure and I'd like to fetch all of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.