October 26, 2015 at 10:53 pm
Comments posted to this topic are about the item SQLCMD connection switching
October 26, 2015 at 11:58 pm
This was removed by the editor as SPAM
October 27, 2015 at 4:41 am
Good question, I like it 🙂
Thanks & Best Regards,
Hany Helmy
SQL Server Database Consultant
October 27, 2015 at 4:48 am
I am completely baffled by being able to get a result for Server2 before it has even been connected to. Can somebody give a better explanation? The one provided is insufficient for me.
October 27, 2015 at 4:53 am
tom.w.brannon (10/27/2015)
I am completely baffled by being able to get a result for Server2 before it has even been connected to. Can somebody give a better explanation? The one provided is insufficient for me.
I agree with Tom..surely answers 2 and 3 are equally plausible. It just depends on what your original connection was?
October 27, 2015 at 4:55 am
David McKinney (10/27/2015)
tom.w.brannon (10/27/2015)
I am completely baffled by being able to get a result for Server2 before it has even been connected to. Can somebody give a better explanation? The one provided is insufficient for me.I agree with Tom..surely answers 2 and 3 are equally plausible. It just depends on what your original connection was?
+1
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
October 27, 2015 at 5:28 am
I never use it, but perhaps it's time for me to look into it.
October 27, 2015 at 7:23 am
The Messages pane gives some insight. Without GO statements, this is one SQL batch. The connect commands are processed in order before any of the SQL is executed.
Connecting to server1\instance1...
Disconnecting connection from server1\instance1...
Connecting to server1\instance2...
Disconnecting connection from server1\instance2...
Connecting to server2\instance1...
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
Disconnecting connection from server2\instance1...
October 27, 2015 at 7:31 am
Stephanie Giovannini (10/27/2015)
The Messages pane gives some insight. Without GO statements, this is one SQL batch. The connect commands are processed in order before any of the SQL is executed.Connecting to server1\instance1...
Disconnecting connection from server1\instance1...
Connecting to server1\instance2...
Disconnecting connection from server1\instance2...
Connecting to server2\instance1...
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
Disconnecting connection from server2\instance1...
Thank you! Now I understand.
October 27, 2015 at 7:58 am
Thanks, Stephanie....makes sense at last!
October 27, 2015 at 3:16 pm
However nowhere does it say we start in Server2/Instance1
October 28, 2015 at 5:41 am
Hi, Paul.
Great question, I did not know the correct altenartive.
October 28, 2015 at 6:54 am
Good to know, thanks.
October 28, 2015 at 7:09 am
wally 96967 (10/27/2015)
However nowhere does it say we start in Server2/Instance1
It doesn't, but that is not really relevant. When parsing the batch, SSMS will execute all the :connect commands in order, so it will end up connected to the last mentioned server regardless of where it was connected first. And then it will send the T-SQL part of the batch to the instance it is connected to.
October 29, 2015 at 3:15 am
Interesting question, thanks.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
Viewing 15 posts - 1 through 15 (of 16 total)
You must be logged in to reply to this topic. Login to reply