Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 ActiveX Script Task in DTS: Sleep

Author  Topic 

Jay99

468 Posts

Posted - 2002-03-11 : 12:19:27
SQL 7 SP2

I need an Step in my DTS Package process flow that simply checks to see if a file exists in a directory and if not sleep for a while (5 sec) and then check again.

I am 97% there (I think), but I am missing the mechanism to do the Sleep. Without the sleep the package pegs the processor. This seems so simple, somebody must have a good (easy) way to do this.

The error I am getting is
quote:

Error Code: 0
Error Source: Microsoft VBScript runtime error
Error Description: Object doesn't support this property or method: 'wscript.sleep'

Error on Line 10



Here is my ActiveX Script tastk


'**********************************************************************
' Main
'************************************************************************

Function Main()

dim wscript
set wscript = createobject("wscript.shell")

while CheckFileExists("d:\test\test.txt") = False
wscript.sleep 5000
wend
Main = DTSTaskExecResult_Success

End Function


'**********************************************************************
' CheckFileExists
'************************************************************************

Function CheckFileExists(sFileName)

Dim FileSystemObject

Set FileSystemObject = CreateObject("Scripting.FileSystemObject")

If (FileSystemObject.FileExists(sFileName)) Then
If (CheckFileDate(sFileName,FileSystemObject) = True) Then
CheckFileExists = True
Else
CheckFileExists = False
End If
Else
CheckFileExists = False
End If

Set FileSystemObject = Nothing

End Function

'**********************************************************************
' CheckFileDate
'************************************************************************

Function CheckFileDate(sFileName, objFSO)

Dim theFile, theDate

Set theFile = objFSO.GetFile(sFileName)
theDate = theFile.DateCreated

If (DateDiff("h", theDate, Now) < 24) Then
CheckFileDate = True
Else
CheckFileDate = False
End If

Set theDate = Nothing
Set theFile = Nothing

End Function


Jay

Jay99

468 Posts

Posted - 2002-03-27 : 09:44:22
Here is how I solved it (I know you have been waiting on the edge of your seat)

alter proc usp_WaitForFiles
@Filename varchar(255),
@Path varchar(255),
@IntervalMins tinyint = 5,
@TotalWaitHours tinyint = 6
as
set nocount on
/******************************************************************************
* Locals
******************************************************************************/
declare
@EndTime datetime,
@FileExistOut int,
@CmdShellRet int,
@WaitForTime datetime,
@Cmd varchar(80),
@File varchar(510),
@ErrTxt varchar(100)

select
@EndTime = dateadd(hh,@TotalWaitHours,getdate()),
@File = @Path + @Filename

/******************************************************************************
* File Exists Logic
******************************************************************************/
exec master..xp_FileExist @File, @FileExistOut OUT

while @FileExistOut = 0 and
@EndTime > getdate()
begin
select @WaitForTime = dateadd(mi, @IntervalMins, getdate())
waitfor time @WaitForTime
exec master..xp_FileExist @File, @FileExistOut OUT
end

-- Time check
if not (@EndTime > getdate())
begin
select @ErrTxt = 'Exceeded total wait time for file ' + @File
raiserror(@ErrTxt,10,1)
return
end

/******************************************************************************
* File Ready Logic
******************************************************************************/
select @Cmd = 'ren ' + @File + ' ' + @Filename + '.recieved'
exec @CmdShellRet = master..xp_cmdshell @Cmd, NO_OUTPUT

while @CmdShellRet = 1 and
@EndTime > getdate()
begin
select @WaitForTime = dateadd(ss, 10, getdate())
waitfor time @WaitForTime
exec @CmdShellRet = master..xp_cmdshell @Cmd, NO_OUTPUT
end

-- Time check
if not (@EndTime > getdate())
begin
select @ErrTxt = 'Exceeded total wait time during copoy of file ' + @File
raiserror(@ErrTxt,10,1)
return
end

select @Cmd = 'ren ' + @File + '.recieved ' + @filename
exec @CmdShellRet = master..xp_cmdshell @Cmd, NO_OUTPUT

-- Rename Error Handler
if @CmdShellRet = 1
begin
select @ErrTxt = 'Error renaming file ' + @File
raiserror(@ErrTxt,10,1)
return
end

return
go



Jay
<O>
Go to Top of Page
   

- Advertisement -