0
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.

2

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.

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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