Vlogs Bengali
Vlogs Bengali

Reputation: 95

USE SSIS package parameter inside script task

I have a script task inside a SSIS package, like this,

public ReadListItemsSPOnline(string siteUrl, string email, string password, int requestTimeout)
        {
            _clientContext = new ClientContext(siteUrl);
            var securePassword = new SecureString();
            foreach (char c in password) securePassword.AppendChar(c);

            String[] BypssArr = { "XXXXXX$" };
            myProxy = new System.Net.WebProxy();
            **myProxy.Address = new Uri("http://abc-proxy-in.abc.net:2020");**
            myProxy.UseDefaultCredentials = true;
            myProxy.BypassList = BypssArr;
            System.Net.WebRequest.DefaultWebProxy = myProxy;
            _clientContext.ExecutingWebRequest += (s, e) =>

            {

                //e.WebRequestExecutor.WebRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");

                e.WebRequestExecutor.WebRequest.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

            };

            _clientContext.Credentials = new SharePointOnlineCredentials(email, securePassword);
            _clientContext.RequestTimeout = requestTimeout;
            _clientContext.Load(_clientContext.Web);
            _clientContext.ExecuteQuery();
        }

As you can see proxy server is hard coded http://abc-proxy-in.abc.net:2020.I want to make the proxy address configurable.I have added a package parameter($project::Proxy_Name) inside my package and I want to use this parameter inside the script task to make it more configurable. Can you let me know what changes should I make in this code to make it more configurable,as I am not a .net person.

Upvotes: 2

Views: 5768

Answers (2)

Richard   Housham
Richard Housham

Reputation: 1680

This might be slightly different depending on your version of Visual Studio. However in VS 2022 go back to your SSIS package (if your not already there) and double click on your script component - this should bring up your script transformation editor. Scroll down and you should see the custom properties and I'm wanting the read only variables. So you can select which variables you want and they will pop up.

enter image description here

You should see something like this.

Click Edit Script and go back to your script. In the newer SSIS the comment at the top says

 * Example of reading from a variable or parameter:
     *  DateTime startTime = Variables.MyStartTime;
     *
     * Example of writing to a variable:
     *  Variables.myStringVariable = "new value";

So go to your code and type Variables. the intellisense should kick in. (if you have done everything correctly). Now you can access the parameters/variables you have made accessible. (all being well in the format you want - date/time, string etc)

Upvotes: 1

KeithL
KeithL

Reputation: 5594

It is right there in the script task on how to use them:

#region Help:  Using Integration Services variables and parameters in a script
    /* To use a variable in this script, first ensure that the variable has been added to 
     * either the list contained in the ReadOnlyVariables property or the list contained in 
     * the ReadWriteVariables property of this script task, according to whether or not your
     * code needs to write to the variable.  To add the variable, save this script, close this instance of
     * Visual Studio, and update the ReadOnlyVariables and 
     * ReadWriteVariables properties in the Script Transformation Editor window.
     * To use a parameter in this script, follow the same steps. Parameters are always read-only.
     * 
     * Example of reading from a variable:
     *  DateTime startTime = (DateTime) Dts.Variables["System::StartTime"].Value;
     * 
     * Example of writing to a variable:
     *  Dts.Variables["User::myStringVariable"].Value = "new value";
     * 
     * Example of reading from a package parameter:
     *  int batchId = (int) Dts.Variables["$Package::batchId"].Value;
     *  
     * Example of reading from a project parameter:
     *  int batchId = (int) Dts.Variables["$Project::batchId"].Value;
     * 
     * Example of reading from a sensitive project parameter:
     *  int batchId = (int) Dts.Variables["$Project::batchId"].GetSensitiveValue();
     * */

Upvotes: 1

Related Questions