SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SSIS Flat File read error retry?


SSIS Flat File read error retry?

Author
Message
csdunaway
csdunaway
SSC Veteran
SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)

Group: General Forum Members
Points: 201 Visits: 238
I am trying to read a flat file in SSIS. If the file is currently locked, I want to be able to wait one second, and try again. I want to continue retrying until the lock is gone.

What is the best way to do this?

Thanks!



Jan Wagner-460740
Jan Wagner-460740
SSC Veteran
SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)

Group: General Forum Members
Points: 293 Visits: 204
Hi,
you could use a scripttask which checks the state of your input file, and if its locked waits for e.g. 1 second.
To prevent the package from running into a deadlock you should limit the number of retries, this could be done using a loop.

Regards,

Jan
Todd Engen
Todd Engen
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2771 Visits: 6336
On the Control Flow canvas add a Script Task and connect that to the Data Flow task.

In the following example the Script Task loops until the file becomes available or a timeout period has expired.


' VB.Net
' Returns success if file can be opened before a timeout period has expired
' Note: Add Imports System.IO at beginning
'

' Replace hardcoded file name with package variable.
Dim strFilename As String = "c:\temp\input.csv"
Dim fsMyFile As System.IO.FileStream
Dim bFinished As Boolean = False
Dim iCount As Integer = 1
dim iTimeout as Integer = 60

Do
Try
fsMyFile = System.IO.File.Open(strFilename,FileMode.Open,FileAccess.ReadWrite,FileShare.None)
bFinished = True
fsMyFile.Close()
Catch ioex As System.IO.IOException
iCount += 1
System.Threading.Thread.Sleep(1000)
End Try

Loop Until bFinished Or iCount > iTimeOut

If bFinished Then
Dts.TaskResult = Dts.Results.Success
Else
Dts.TaskResult = Dts.Results.Failure
End If


csdunaway
csdunaway
SSC Veteran
SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)

Group: General Forum Members
Points: 201 Visits: 238
Thank you both! I just implemented this script and it works perfect!

Thank you SQLServerCentral.com for this forum to allow users to help each other.



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search