Run EXE from Stored Procedure

  • Hi,

    Is any way to run any EXE file from SQL Server 2000 >> Stored Proc

    Thanks

  • Might want to put this in a SQL Server 2000 forum, but here's a head start:

    http://www.codeproject.com/KB/database/xyprocedure.aspx

  • include following script in your Stored Proc

    declare @sqlcmd varchar(200)

    SET @SQLCmd = 'copy c:\dba\sampl.xls c:\dba\sampl_2.xls'

    EXEC master..xp_cmdshell @SQLCmd , no_output 🙂

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • getshir (9/22/2008)


    Is any way to run any EXE file from SQL Server 2000 >> Stored Proc

    XP_CMDSHELL is all you need.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • master..xp_cmshell

    executed above command ..

    query result shows me..query executed succesfully..but file is not copied

  • You should verify that the security context under which you are running xp_cmdshell has rights on the file system where you are trying to copu a file.

  • You do realize that this executes on the Server and not on the Client, right?

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Excerpt from http://www.databasejournal.com/features/mssql/article.php/3372131

    "Now not just anyone can run this extended stored procedure. If you want to execute this extended stored procedure, you will either need to be a member of the sysadmin role, or have the xp_sqlagent_proxy_account set up on your SQL Server. If a login executing this extended stored procedure is a member of the sysadmin role then the submitted command will run under the security context associated with the SQL Server Service account in which it runs. If the login executing this procedure is not a member of the sysadmin role, then the command uses the xp_sqlagent_proxy_account login security context for determining whether operating system commands can and cannot be run. If there is no xp_sqlagent_proxy_account then using this procedure will fail for all users not in the sysadmin role. "

    Assuming that we are in the case when xp_cmdshell is running under security context of the SQL server service account, you also has to make sure that this account INDEED have security rights on the file system where you are trying to copy a file.

  • Hi,

    I have an EXE file which i would like to run, what i am doing is running following script but in void.... 🙁

    declare @sqlcmd varchar(200)

    SET @sqlcmd = 'WinWSSList.exe'

    EXEC master..xp_cmdshell @sqlcmd

    Now what it gives me as output is :

    'WinWSSList.exe' is not recognized as an internal or external command,

    operable program or batch file.

    NULL

    What to do ??

    Thanks

    Parth

  • parth83.rawal (10/2/2009)


    Hi,

    I have an EXE file which i would like to run, what i am doing is running following script but in void.... 🙁

    declare @sqlcmd varchar(200)

    SET @sqlcmd = 'WinWSSList.exe'

    EXEC master..xp_cmdshell @sqlcmd

    Now what it gives me as output is :

    'WinWSSList.exe' is not recognized as an internal or external command,

    operable program or batch file.

    NULL

    What to do ??

    Thanks

    Parth

    It's telling you that it cannot find this exe file. Be sure to include the path to this EXE. And remember that this is executed on the Server, and not on your Client.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Hi,

    First of all thanks for the prompt reply.

    My EXE is in C Drive only, and it is running fine, if i run from the command prompt.

    and my server and exe both are on server only. some how it is not running.

    Thanks

    Parth

  • try using full path of the executable. So instead of

    SET @sqlcmd = 'WinWSSList.exe'

    use

    SET @sqlcmd = 'C:\WinWSSList.exe'

    @sqlcmd session may open a command prompt somewhere in the binn folder of the SQL where your executable does not exist.

  • parth83.rawal (10/2/2009)


    My EXE is in C Drive only, and it is running fine, if i run from the command prompt. and my server and exe both are on server only. some how it is not running.

    What makes you think that the xp_cmdshell process's starting directory is "C:\"? It probably isn't, which is why should try what I suggested and specify the full path.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Do you till have this problem?

    'WinWSSList.exe' is not recognized as an internal or external command,

    operable program or batch file.

    NULL

    By this statement, I understand the 'WinWSSList.exe' cant be executed from Command Prompt.

    Try executing this from command prompt.

    Regards,

    Gautham Akula

  • indeed it is working from command prompt but not working from SQL, 🙁

    and then i changed my approach.....but still i would like to know the answer for that. 🙂

    Thanks

    Parth

Viewing 15 posts - 1 through 15 (of 15 total)

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