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 7681953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:27:33+00:00 2026-05-31T18:27:33+00:00

I have a C# script task in SSIS that I can pass a variable

  • 0

I have a C# script task in SSIS that I can pass a variable to no problem. I have another class that I created in the script call otherclass.cs. How do I use the variable within otherclass.cs?

I tried to just do this:

_urlBase = Dts.Variables["User::URLBase"].Value.ToString();

But I get this error:

The name 'Dts' does not exist in the current context

I’m pretty new to C# and classes so I may not be asking the question correctly. Is what I’m asking even possible?

Thanks.


SOLUTION

Here is my solution to what I was trying to accomplish:

In ScriptMain.cs created new service like this:

OtherService ws = new OtherService(Dts.Variables["User::URLBase"].Value.ToString());

In the OtherService.cs I had this:

class OtherService
{
    public OtherService(string urlBase)
    {
        _urlBase = urlBase;
        //do other stuff
    }
    //other methods and stuff
}
  • 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-05-31T18:27:35+00:00Added an answer on May 31, 2026 at 6:27 pm

    When you add a C# Script Task in BIDS 2008, notice this line in the ScriptMain task that it generates for you:

    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    

    This says that ScriptMain is a subclass of Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase. That base class (VSTARTScriptObjectModelBase) defines a member Dts of type Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptObjectModel. This in turn has a member named Variables. That is what you are accessing when you type “Dts.Variables” in ScriptMain.

    The class you define in “otherclass.cs” is not a subclass of VSTARTScriptObjectModelBase and therefore does not inherit its member Dts. That is why the compiler tells you “The name ‘Dts’ does not exist in the current context.”

    If otherclass needs access to a variable’s value then as cfrag suggests you can pass this value in when you instantiate a member of your class or when you call the class member function that needs this value. If you will need to access multiple variables, consider something like this:

    public otherclass(Microsoft.SqlServer.Dts.Runtime.Variables dtsVariables)
    {
        DtsVariables = dtsVariables;
        // other stuff
    }
    private Microsoft.SqlServer.Dts.Runtime.Variables DtsVariables;
    

    Now otherclass has an instance member named DtsVariables which its non-static members can use to access the Variables collection passed in when the object was created. You would instantiate it and call methods from ScriptMain like this:

    otherclass oc = new otherclass(Dts.Variables);
    string url = oc.MakeURL();
    

    Inside otherclass.MakeURL(), you can use the instance variable DtsVariables like you would have used Dts.Variables in ScriptMain, e.g.:

    public string MakeURL()
    {
        return DtsVariables["User::URLBase"].Value.ToString() + "/default.aspx";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script task that executes a dynamically created SQL restore statement. This
SSIS (SQL 2005) packages that have a script task that invoke custom .NET dlls
In SSIS 2008 I have a Script Task that checks if a table exists
I have a script task in an SSIS package that is supposed to retrieve
I have a script task (VB 2008) inside an SSIS dtsx package that I'm
I have script which allows to display Bing search results. I can call for
I have a script that can lookup and output or write my current release
I have a SSIS Script Task written in C# and I want it ported
Does anyone know how to execute a PowerShell script from SSIS? I have created
I am working on an SSIS package that uses a c# script task. For

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.