0

In SSIS script task, how Can I get all package level variables value at run-time using DTS library or any other way, without adding ReadOnlyVariables or ReadWriteVariables. I need latest/updated values.

1

1 Answer 1

1
using RuntimeWrapper = Microsoft.SqlServer.Dts.Runtime.Wrapper;  

namespace ST_9646389d9def4d9b8d8b53a9ae45fc56
{

    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {


    public void Main()
            {
       RuntimeWrapper.IDTSProject100 p = ((RuntimeWrapper.IDTSProject100)((Package)Dts.Variables["User::AnyReadOnlyVariable"].Parent).Project);
       Project proj = GetProject(p);

      foreach (PackageItem pkgItem in proj.PackageItems)
                    {
                        gdicLogData = new Dictionary<string, string>();

                        Package pkg = pkgItem.Package;
                        Variables varPackageValiables = pkg.Variables;

                        foreach (Variable pkgVar in varPackageValiables)
                        {

                            if (pkgVar.Namespace.ToString() == "User")
                            {

                                Dictionary.Add(pkgVar.Name, pkgVar.Value.ToString());
                            }
                        }


                        Parameters parameters = pkg.Parameters;

                        foreach (Parameter parItem in parameters)
                        {
                            Dictionary.Add(parItem.Name, parItem.Value.ToString());
                        }


                    }

    }

}
}

==================

 private Project GetProject(RuntimeWrapper.IDTSProject100 proj)
    {
        System.Reflection.PropertyInfo pInfo = proj.GetType().GetProperty("Project",
        System.Reflection.BindingFlags.Public |
        System.Reflection.BindingFlags.NonPublic |
        System.Reflection.BindingFlags.Instance);
        Project prj = (Project)pInfo.GetValue(proj, null);  

        return prj;
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Nice idea! Small clarification -- User::AnyReadOnlyVariable has to be defined on Package level.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.