Take the 2-minute tour ×
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. It's 100% free, no registration required.
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.

share|improve this question

2 Answers 2

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

 
discard

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.