Error using bcp command with xp_cmdshell

1

I am trying to use the command bcp by means of a query with xp_cmdshell the problem when executing it I skipped an error of Unable to open the file. But if I execute the same by command lines it works perfectly. The user I'm using has sysadmin permissions

  exec xp_cmdshell 'bcp "Prueba.dbo.tabla" out "C:\Users\Usuario\Documents\prueba.txt" -c -T -t -r'

The error that shows me is this

    
asked by Jose Yeste 16.11.2017 в 09:49
source

1 answer

1

The error is per issue of permissions, what I have done so that it works for me is to execute the query exec master..xp_cmdshell 'whoami' and the user tells you to execute the command, what you have to do is add permissions to that user to the folder that you want to access.

If it does not work, you can change the user with whom you start the sql server session in control panel > Administrative tools > Services > Search Sql Server (In my case SQL Server MSSQLSERVER) > in the tab login session put the one you want

    
answered by 16.11.2017 в 11:24