all groups > sql server dts > september 2005 >
You're in the

sql server dts

group:

Error handling of file in use


Error handling of file in use Stijn Verrept
9/30/2005 5:08:48 AM
sql server dts:
I read import a text file and need to delete it afterwards. I don't
know any VBScript so I had to look up some code to delete it. I found
the following:

'**********************************************************************
' Visual Basic ActiveX Script
'***********************************************************************
*
Option Explicit

Function Main()
Dim oFSO
Dim sSourceFile

Set oFSO = CreateObject("Scripting.FileSystemObject")

sSourceFile = "C:\Output.txt"

' Check if file exists to prevent error
If oFSO.FileExists(sSourceFile) Then
oFSO.DeleteFile sSourceFile
End If

' Clean Up
Set oFSO = Nothing

Main = DTSTaskExecResult_Success
End Function


However, it could be that the file is locked and the delete fails. In
that case I need the DTS package to sleep for a couple of seconds and
then try again. How do I do this?


Thanks in advance,

Re: Error handling of file in use Stijn Verrept
9/30/2005 5:44:23 AM
[quoted text, click to view]

Thanks for your reply. I cannot delete the same file the next time
because then I will have doubles in the database. Another application
Re: Error handling of file in use irfankhanpatha via SQLMonster.com
9/30/2005 10:16:40 AM
Do error trapping the same by using err.number . If the file is in use than
skip the deleting process. You can delete the same file the next time when u
run function (That means at the starting of the function before using the
file.).

[quoted text, click to view]
AddThis Social Bookmark Button