Batch file in SQL Procedure

  • 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....

  • 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 ?

    [font="Tahoma"]
    --SQLFRNDZ[/url]
    [/font]

  • Could also be a permissions issue. Does the account running the SQL Server Service have access to that folder?

  • 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!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply