I have enabled the XP_CMDSHELL and tried to execute the following line of code:
EXEC Master..XP_CMDSHELL 'bcp "exec server.db.dbo.SProc" queryout c:\test\test.txt -k -t \t -c -S localhost -T';
but I got the following error:
SQLState = 37000, NativeError = 7202
Error = [Microsoft][SQL Server Native
Client 10.0][SQL Server] Could not find
server in sysservers. Execute
sp_addlinkedserver to add the server
to sysservers.
But when I execute the stored procedure outside XP_CMDSHELL it works fine.
Any suggestions?
Bear in mind
xp_cmdshellexecutes in the context of the SQL Server machine you call it from.It sounds like the server is not listed on the actual server machine running your SQL Server. If it is on the same server you are calling it from, try using
localhostor the internal IP address.