April 5, 2002 at 8:53 am
I am trying to write a trigger that whenever a row is added to a table, the AI Trigger will execute the XP..CMDSHELL. This will then launch OSQL to create a text file and execute a batch for sending SNMP Trap.
Any help?
April 5, 2002 at 11:07 pm
here is an example for you...
create table t(i int)
go
create trigger ins on t
for insert
as
declare @sql varchar(255)
--create batch file
select @sql='echo dir ^>c:\out.txt >c:\r.bat'
exec master..xp_cmdshell @sql, no_output
--execute batch file
select @sql='c:\r.bat'
exec master..xp_cmdshell @sql, no_output
go
insert t values(1)
go
--
-oj
April 6, 2002 at 8:32 am
Per zishanz in thread http://www.sqlservercentral.com/forum/topic.asp?TOPIC_ID=3430&FORUM_ID=23&CAT_ID=2&Topic_Title=bcp%20/%20how%20to%20run%20bcp%20from%20within%20a%20sp&Forum_Title=General
quote:
Can I use xp_cmdsehll inside my stored procedure?The book(Microsfot SQL Server 2000 DBA Survival Guide) p 409 says:
'Do not use xp_cmdshell to call BCP from within a user-defined transaction in a stored procedure. Doing so can lead to endless blocking!'
This applies to triggers as well.
"Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply