question

Chris 2 avatar image
Chris 2 asked

Why script task failed?

Hi, I am on Windows 2008 and SQL 2012. SSIS script task has following: If (File.Exists(FullFilePathName)) Then Dts.Variables.Item("User::File_Exists").Value = True Else Dts.Variables.Item("User::FileExist").Value = False End If Dts.TaskResult = ScriptResults.Success It works fine when file exists. Step failed when file is not there. I thought it should just set File_Exists to correct value and go onto next step. What did I miss? How to continue without error out? Many thanks for any hint. Chris
ssissql-server-2012
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Wimbush avatar image
David Wimbush answered
Just a stab in the dark, really, but instead of the IF statement maybe you could just assign the result to the variable like this: Dts.Variables.Item("User::File_Exists").Value = (File.Exists(FullFilePathName))
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Scot Hauder avatar image Scot Hauder commented ·
This should fix it...the step was failing because the user variables are different--he is missing an underscore. brings back memories of searching for hours through C code to find that i had: if (x=1) instead of: if (x==1) the code will compile and run, but not behave as expected ... I can say that only happened once !
1 Like 1 ·
David Wimbush avatar image David Wimbush commented ·
Good spot! I didn't see that. Usually that thing only trips me up when it's my own code I'm reading.
0 Likes 0 ·
Chris 2 avatar image
Chris 2 answered
David and Scott, Many thanks for the help. I also tried following and worked: If Dts.Variables.Contains("User::FilePath") = True AndAlso _ Dts.Variables.Contains("User::FileName") = True Then If File.Exists(FilePath + fileName) Then Dts.Variables.Item("User::File_Exists").Value = True 'System.Windows.Forms.MessageBox.Show("File exists") Else Dts.Variables.Item("User::File_Exists").Value = False 'System.Windows.Forms.MessageBox.Show("File not exists") End If Dts.TaskResult = ScriptResults.Success Else Dts.TaskResult = ScriptResults.Failure End If Chris
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.