Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need a query in SQL using Trigger to Alert an insert item to a table which blongs to sharePoint database (AllUserData) with an exact List-Id and then execute an exe. file ?
I mean after alerting an insert I want to execute an .exe file in a begin-end block of Trigger.

Thank U for your help
Posted
Updated 30-Dec-14 20:18pm
v2

1 solution

Hi,

1. Enable the execution of xp_cmdshell feature
2. Create trigger that execute selected exe file

hope that help,
Béchir.


USE [TEST]
GO

DROP TABLE [dbo].[table1]
GO

-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1;
GO
-- To update the currently configured value for advanced options.
RECONFIGURE;
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1;
GO
-- To update the currently configured value for this feature.
RECONFIGURE;
GO

--Create table1
CREATE TABLE dbo.table1(
	table_id int IDENTITY(1,1) NOT NULL,
	table_desc nvarchar(50) NULL,
)
GO

CREATE TRIGGER after_insertData
   ON TEST..table1
   AFTER INSERT
AS 
BEGIN
	declare @strcmdshell nvarchar(200)= N'C:\Windows\notepad.exe';
	exec master..xp_cmdshell @strcmdshell
END
GO
 
Share this answer
 
Comments
Mohamad hashemi 3-Jan-15 0:26am    
how to verify if a new row is inserted and its 'tp_ListId' column has a value of N'{622E1A8C-A706-46BA-A3C7-D62A08972E0E}' ????
BechirBenltaief 4-Jan-15 8:46am    
hi,
you can insert "tp_ListId" value in history table in the same or another database table.
for the value, i think the type of "tp_listId" is GUID, so you can't predict his value.

to find the insert value of "tp_listId" add in your trigger "select tp_listId from INSERTED"

hope that help
Bechir.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900