We recently moved all databases from MyServerA
to MyServerB
. Everything worked fine on MyServerA
, but when I try to call the bcp
command using xp_cmdshell
, I get the following error:
Error = [Microsoft][SQL Server Native Client 11.0]Unable to open BCP host data-file
Some Info:
I'm pretty sure the user I'm logged in as under
MyServerB
has rights assigned to the remote server location I'm trying to post to. I ran a "whoami" at the command prompt and successfully added them under security with full control on the remote folder (which btw is shared). Plus, I can map to it or access it fine.Interestingly when trying to send an already existing file, that is from the same location I'm trying to send to, as an attachment using
sp_send_dbmail
in, I got anAccess denied
message. So it seems a security issue. But see #1 above.I also tried saving it in a folder on the local
MyServerB
, but I cannot do that either.
Sample Code:
DECLARE @bcp varchar(2000);
SET @bcp = 'bcp "SELECT 1" queryout "\\MyServerA\Reports\MyFile.txt" -c -T -S MyServerB';
EXEC master..xp_cmdshell @bcp;