Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Batch file in SQL Procedure


Batch file in SQL Procedure

Author
Message
Minnu
Minnu
Old Hand
Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)

Group: General Forum Members
Points: 305 Visits: 950
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....
@SQLFRNDZ
@SQLFRNDZ
Mr or Mrs. 500
Mr or Mrs. 500 (523 reputation)Mr or Mrs. 500 (523 reputation)Mr or Mrs. 500 (523 reputation)Mr or Mrs. 500 (523 reputation)Mr or Mrs. 500 (523 reputation)Mr or Mrs. 500 (523 reputation)Mr or Mrs. 500 (523 reputation)Mr or Mrs. 500 (523 reputation)

Group: General Forum Members
Points: 523 Visits: 1175
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

SQLMD
SQLMD
SSC-Addicted
SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)SSC-Addicted (458 reputation)

Group: General Forum Members
Points: 458 Visits: 423
Could also be a permissions issue. Does the account running the SQL Server Service have access to that folder?
kevaburg
kevaburg
Mr or Mrs. 500
Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)

Group: General Forum Members
Points: 563 Visits: 912
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!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search