Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

trouble passing variable into package

$
0
0

I am having an issue reading a variable in a script task that I'm passing in from a windows service. I should be able to pass the param in from .NET and load it into one of my package vars right? The windows service is a file watcher service.

Windows Service code

                    Package pkg;
                    Application app;
                    DTSExecResult pkgResults;
                    Variables vars;

                    app = new Application();
                    pkg = app.LoadPackage(pkgLocation, null);d because I log it to a log file.

                    vars = pkg.Variables;

                    vars["User::FileName"].Value = sFileName.ToString();
                    pkgResults = pkg.Execute(null, vars, null, null, null);

The sFileName variable in the service is populated because I write it to a log file.

In the package I list the FileName variable as read/write. Have checked the spelling.

package code snippet:

      public void Main()
      {
      //get file and path info
      string sFileName = Dts.Variables["User::FileName"].Value.ToString();

the package fires but the variable is empty and I log an exception to the sysssislog:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.  Parameter name: length     at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)     at ST_5a4733488a6149abb109d633296e2c38.csproj.ScriptMain.Main()     --- End of inner exception stack trace ---     at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)     at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)     at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)     at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

I cannot find what the issue is. In the package I log to a text file the value of FileName variable and as expected it is empty.

I appreciate your help wit

       

     


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>