Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Batch file in SQL Procedure Expand / Collapse
Author
Message
Posted Friday, May 17, 2013 1:33 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, August 5, 2014 10:09 AM
Points: 227, Visits: 713
Hi Team,

Am trying to call a batch in sql server stored proc.

CREATE PROCEDURE test_batch
AS
BEGIN
declare @bat varchar(200)
set @bat = 'd:\test\test.bat'
exec master..xp_cmdshell @bat
END


but am getting below error

-- The system cannot find the path specified.
-- NULL

Can u please help me....
Post #1453878
Posted Friday, May 17, 2013 1:38 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Sunday, August 17, 2014 8:42 PM
Points: 463, Visits: 1,030
Minnu (5/17/2013)
Hi Team,

Am trying to call a batch in sql server stored proc.

CREATE PROCEDURE test_batch
AS
BEGIN
tdeclare @bat varchar(200)
set @bat = 'd:\test\test.bat'
exec master..xp_cmdshell @ba
END


but am getting below error

-- The system cannot find the path specified.
-- NULL

Can u please help me....


Either the path is incorrect or running from a wrong server...I believe from the error I see. Is this d:\ is on the same server your instance is running on ?



--SQLFRNDZ
Post #1453881
Posted Friday, May 17, 2013 9:34 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, June 26, 2014 7:20 AM
Points: 442, Visits: 410
Could also be a permissions issue. Does the account running the SQL Server Service have access to that folder?
Post #1454067
Posted Friday, May 17, 2013 11:15 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: 2 days ago @ 5:18 AM
Points: 311, Visits: 486
I'd like you to think about this a Little differently:

a. Do the Contents of test.bat contain Windows-based scripts? If so, would it not be better to create a Scheduled/On-Demand Job from within Windows?

OR

b. Does the script contain SQL code? If so, would it not be better to runn it under the SQL Server Agent?

As for your error message itself, it is clear that the stored procedure cannot find the file under that path. To that end, have you:

a. Connected to a remote instance using another Server? If so, the calling instance is looking for the file on the wrong Server.

OR

b. checked that the calling account is being denied Access to the file because of incorrect Permissions (even at the NTFS-Level) or is the calling user a member of a role that does not allow browsing for files? I think this solution is less likely but still worth investigating maybe!
Post #1454231
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse