Xp_cmdshell bcp wont save file

bcp

EXEC xp_cmdshell 'bcp "SELECT lastconnectip FROM RF_USER.dbo.tbl_UserAccount" queryout "C:\test.txt" -T -c' 

The command above runs, the output:

NULL
Starting copy...
1000 rows successfully bulk-copied to host-file. Total received: 1000
NULL
1158 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total     : 1      Average : (1158000.00 rows per sec.)
NULL

But no file is actually written. what am i missing? The user does have full rights (sysadmin) SQL 2008 R2.

Also alternative way to use NETSH in sql query/trigger would work aswell instead of the one above.

Best Answer

You probably look for the file on the client computer. xp_cmdshell executes on the server, so look for C:\test.txt on the SQL Server machine.

Related Question