If I connect to server "ServerA.domain.com" and execute the following in SQLCMD mode of SQL Management Studio:
EXEC xp_cmdshell 'hostname'
:CONNECT ServerB.domain.com
EXEC xp_cmdshell 'hostname'
Then the output is:
Connecting to ServerB.domain.com...
output
---------------------------------------
ServerB
NULL
(2 rows affected)
output
------------------------------------------
ServerB
NULL
(2 rows affected)
Disconnecting connection from ServerB.domain.com...
It appears to execute the :CONNECT command prior to the first xp_cmdshell command, despite the sequence of the script. What is the reason for this, and can it be prevented?