Solved How can i run a batch file (.bat) using SQL Triggers

May 2, 2017 at 06:25:56
Specs: Windows 7, 4 GB
Hi,
I am trying to run a .bat file stored in a D:\ drive using SQL triggers.
when some operation occurs in a table this trigger need to be fired and Batch file has to be executed.
for the i have created a sample trigger.

Create TRIGGER [dbo].[TestBatch] ON [dbo].[RawMaterial]
FOR UPDATE
AS
DECLARE @PassedVariable VARCHAR(100)
DECLARE @CMDSQL VARCHAR(1000)
begin
--SET @PassedVariable = 'SqlAuthority.com'
SET @CMDSQL = 'D:\AutoServer.bat'-- + @PassedVariable
EXEC master..xp_CMDShell @CMDSQL
end

but i am not getting a proper output. when i run the above script it is giving some error message saying.
"The device is not ready.
NULL"

I would request all to give me a solution for my above issue.

Thanks in advance.


See More: How can i run a batch file (.bat) using SQL Triggers

Report •

#1
May 11, 2017 at 00:11:37
✔ Best Answer
Create TRIGGER [dbo].[TestBatch] ON [dbo].[RawMaterial]
FOR UPDATE
AS
DECLARE @PassedVariable VARCHAR(100)
DECLARE @CMDSQL VARCHAR(1000)
begin
--SET @PassedVariable = 'SqlAuthority.com'
SET @CMDSQL = 'D:\AutoServer.bat'-- + @PassedVariable
EXEC master..xp_CMDShell @CMDSQL
end

Report •
Related Solutions


Ask Question