Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script Task for file exist not working 1

Status
Not open for further replies.

Ringers

Technical User
Feb 26, 2004
180
AU
Hi All,
I have script task designed to look if a .xls file exists or not. It works correctly when the file is in network folder, but when it doesn't the False path doesn't fire. It still thinks it should look for the file and produces a check object exists error.

Package uses two variables;

@BolFileExists, Package, Boolean, False
@strFileLocation, Package, String, D:\xxxx\yyyy\aa.xls

Script Task: Readonly User::strFileLocation, Read Write User::BolFileExists
Code:
Imports System.IO



Public Class ScriptMain


    Public Sub Main()

        Dts.Variables("BolFileExists").Value = File.Exists(Dts.Variables("strFileLocation").Value.ToString())

        Dts.TaskResult = Dts.Results.Success



    End Sub



End Class

vxjmnk.jpg

8yi5xs.jpg

2dgut4w.jpg
 
I would use a breakpoint to look at the variables at the point after this script runs (use the breakpoint within SSIS not in the script). What is the var saying - true or false?

----------------------------------------

Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Bernard Baruch

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
I'm suprised you don't get an error in the script task (in fact you probably are but it is getting masked by the Dts.TaskResult = Dts.Results.Success line

you are attempting to set a boolean variable equal to a string

try this instead

Code:
Dts.TaskResult = Dts.Results.Success
Try

Dts.Variables("BolFileExists").Value = File.Exists(Dts.Variables("strFileLocation").Value)

Catch ex as exception
'comment this out in production but use for testing
'should probably have some error handling here in case something goes wrong (access to LAN etc)
msgbox (ex.message.tostring)
Dts.TaskResult = Dts.Results.failure

end try

I cannot emphasise enough the importance of error handing and the usage of TRY/CATCH constructs when writing code for ETL processes

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Good spot Geoff - didnt notice that!

Very wise words about the error handling. I would go as far as to say all scripts should have a Dts.Results.failure
somewhere!

----------------------------------------

Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Bernard Baruch

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
agreed - should always be able to handlefailures gracefully even if youexpect no failure can occur

In this instance you could hae a communication link failure to the LAN which would cause an error with the file.exists and therefore should be able to be trappd and reported

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top