October 16, 2007 at 11:42 am
A pdf file is generated by an application. I need a trigger to change the name of that file right after it is created. The problem is that the file can take 0.5 - 5seconds to generate. My code (below) works except when the file takes too long to create, so it is not there to rename. Is there a way to watch for the file, or pause 5 seconds?
Thanks, Jim
******************************
ALTER trigger requests_draft_tracking on requests
for update
not for replication
as
if update (req_stat) and ((select top 1 req_stat from inserted)='Draft') and ((select top 1 req_stat from inserted) <> (select top 1 req_stat from deleted))
begin
DECLARE @cmd varchar(4000)
select @cmd= 'rename "\\Osp-limsghq\jtrax\finalreports\'+ RTRIM(r.case_id)+'-'+r.req_num+'.PDF" "d'+ RTRIM(r.case_id)+'-'+r.req_num+'.PDF"' from inserted i,requests r where r.rowguid = i.rowguid
EXEC master..xp_cmdshell @cmd
end
October 16, 2007 at 2:58 pm
Doing a trigger for this is a bad idea, exactly for the reason you are encountering. Can you not do the rename in the program code? If not, you may be better off making an asynchronous process where you dump the info into a table and then have a job or process read the table and perform the rename.
K. Brian Kelley
@kbriankelley
October 16, 2007 at 3:26 pm
Even though I also agree that this should not be done in T-SQL, here is a method to wait for 5 seconds:
WAITFOR DELAY '00:00:05'
Best Regards,
Chris Büttner
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply