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
 Transact-SQL (2000)
 triggers xp_cmdshell and tablock

Author  Topic 

Neilmcse
Starting Member

1 Post

Posted - 2004-08-25 : 21:32:28
I have a requirement that as a record is inserted into one of my tables, an external command line batch file must be run. I would like to have a lock on the table so that there are now inserts on the table until the batch file completes. I know that this will have negative perfomance implications but I need to do it none the less. The creation of the trigger and the xp_cmdshell portion is really straight forward but I am not sure how I can set the tablock. Any help?

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-08-25 : 23:30:19
[code]
CREATE TABLE #cmdshell(result VARCHAR(8000))

BEGIN TRANSACTION

INSERT table(columnlist)
SELECT column1, column2 FROM table2

INSERT #cmdshell(result)
EXEC xp_cmdshell 'dir c:\'

COMMIT TRANSACTION

--This effectively does what you want IF the batch file returns a result set or completion status. There are some java apps and other programs this won't work with because they operate in a different context.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -