cmd_shell..error

  • When am trying to execute the following through AppUser

    SET @sql='bcp test.dbo.output out E:test\file1 -c Smegha -Usa -Pabc123'

    EXEC master..xp_cmdshell @sql

    am getting the following error mesg.

    Server: Msg 229, Level 14, State 5, Procedure xp_cmdshell, Line 25

    EXECUTE permission denied on object 'xp_cmdshell', database 'master', owner 'dbo'.

     

    when I use the same AppUser in a diff SP to run the following, I have no problem.

    EXEC master..xp_cmdshell 'ren "E:\Nasid\Archive\'+abc+'.txt" '

    What might be the reason?

     

  • Well, first of all, your second command isn't even a valid command so there's no way that it would be working for you susccessfully. You can not use string concatenation in the value that you are passing in to xp_cmdshell. You have to use a complete literal string or perform the concatenation in a variable set command and pass in just the variable to xp_cmdshell.

    By default, you have to have sa rights to use xp_cmdshell though permissions to execute can be assigned to different roles.


    My blog: SQL Soldier[/url]
    SQL Server Best Practices:
    SQL Server Best Practices
    Twitter: @SQLSoldier
    My book: Pro SQL Server 2008 Mirroring[/url]
    Microsoft Certified Master: SQL Server, Data Platform MVP
    Database Engineer at BlueMountain Capital Management[/url]

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

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