I have a very simple SSIS package that reads an environment variable, assigns it to a variable that is sent in an email, and also logs it to a text file. If I execute the package on the server via DTExecUI, it works fine as expected. However, if I schedule it as part of a job, I get the following error:
Code: 0x00000002 Source: Script Task Description: The script threw an exception: Object reference not set to an instance of an object. End Error DTExec: The package execution returned DTSER_FAILURE (1). Started: 9:08:00 AM Finished: 9:08:01 AM Elapsed: 0.859 seconds. The package execution failed. The step failed.
The script is as follows:
Imports
SystemImports
System.DataImports
System.IOImports
Microsoft.SqlServer.Dts.Runtime
Public
Class ScriptMainPublic Sub Main()
Dim Path As String = "C:\TestEnv.txt"
Dim Env As String = Environment.GetEnvironmentVariable("SSISConfig").ToString()
Dim Sw As StreamWriter
Dts.Variables("SSISConfig").Value = Env
If File.Exists(Path) = False Then
Sw = File.CreateText(Path)
Else
Sw = File.AppendText(Path)
End If
Try
Sw.WriteLine(Env)
Finally
Sw.Close()
End Try
Dts.TaskResult = Dts.Results.Success
End Sub
End Class
I have puttered with this for a while now and can't figure out what the problem is. Any ideas