views:

1205

answers:

2

I have a script component which I need to reference a global variable? I guess I can dtsconfig file. How do I set this and read it back out from my script component?

+1  A: 

From http://blogs.conchango.com/jamiethomson/archive/2005/02/09/964.aspx :

Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain
  Public Sub Main()
    Dim vars As Variables
    Dts.VariableDispenser.LockOneForWrite("vMyVar", vars)
    vars(0).Value = "Hello World"
    vars.Unlock()
    Dts.TaskResult = Dts.Results.Success
  End Sub
End Class

Some more discussion:

http://www.developerdotstar.com/community/node/313

http://www.developerdotstar.com/community/node/512

Cade Roux
+1  A: 

You can use

Me.Variables.YourVariableName

this will work only in script component of Data Flow task. In script task you can use like this:

Dts.Variables("YourVariableName").Value.ToString

All you need is to configure the package variable in the dts config file by specifying the value.