Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
EXEC xp_cmdshell 'bcp "SELECT lastconnectip FROM RF_USER.dbo.tbl_UserAccount" queryout "C:\test.txt" -T -c' 

The command above runs, the output:

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

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.

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer

For sysadmins, xp_cmdshell runs the command as the SQL database engine service account.

Make sure that account has been granted write permissions on the target location.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.