C
CSharp Enthusiast
Guest
Hi, I am trying not to hard code values in the script task and use SSIS variables instead for the below code. The issue I run into is unable to call the SSIS package variable outside the main() method.
Error: Dts.Variables["User:ath"].Value.ToString() when used outside the main method gives the error A field initializer cannot reference the non-static field, method, or property 'VSTARTScriptObjectModelBase.Dts'
Is there a work around this?
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
static ScriptMain()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name.Contains("ssisHelper"))
{
string path = @"c:\temp\"; //change the path using a package variable.
return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "ssisHelper.dll"));
}
return null;
}
}
Thank you
SQLEnthusiast
Continue reading...
Error: Dts.Variables["User:ath"].Value.ToString() when used outside the main method gives the error A field initializer cannot reference the non-static field, method, or property 'VSTARTScriptObjectModelBase.Dts'
Is there a work around this?
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
static ScriptMain()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name.Contains("ssisHelper"))
{
string path = @"c:\temp\"; //change the path using a package variable.
return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "ssisHelper.dll"));
}
return null;
}
}
Thank you
SQLEnthusiast
Continue reading...