not able to use xp_cmdshell...

  • Hello,

    I'm trying to read a folder located on another server.

    1. I have created a credential (Identity is <domainname>\<username>

    2. I have created a proxy (Operating System cmdExec) associated with the credential.

    I'm using the following command

    GRANT exec ON xp_cmdshell TO <credential>

    set @strcmd = 'dir '+@strFolder + '*.*'

    exec @result = xp_cmdshell @strcmd

    and I get this :

    Msg 4629, Level 16, State 10, Procedure ImportAvailabilities, Line 33

    Permissions on server scoped catalog views or system stored procedures or extended stored procedures can be granted only when the current database is master.

    Why ???

    Tks for your help !

  • DZN (3/14/2011)


    Hello,

    I'm trying to read a folder located on another server.

    1. I have created a credential (Identity is <domainname>\<username>

    2. I have created a proxy (Operating System cmdExec) associated with the credential.

    I'm using the following command

    GRANT exec ON xp_cmdshell TO <credential>

    set @strcmd = 'dir '+@strFolder + '*.*'

    exec @result = xp_cmdshell @strcmd

    and I get this :

    Msg 4629, Level 16, State 10, Procedure ImportAvailabilities, Line 33

    Permissions on server scoped catalog views or system stored procedures or extended stored procedures can be granted only when the current database is master.

    Why ???

    This is by design, check here... http://msdn.microsoft.com/en-us/library/ms186717.aspx

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • so how to implement ? What's the solution ?

  • DZN (3/14/2011)


    so how to implement ? What's the solution ?

    Make master your current database.

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • Tks will do this.

    Now from a general perspective, could I do this temporarely ? What happens is another SP would do the same at the same time for another db?

  • Can you not put at the top of the script

    Use [Master]

    go

    Would be a lot simpler

  • OK. Good idea

Viewing 7 posts - 1 through 6 (of 6 total)

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