In SQLCMD mode, should CONNECT be an implicit batch separator?

Hi Folks,

I've been working with SQLCMD mode again today and one thing about it always bites me. If I execute a script like:

:CONNECT SERVER1

SELECT @@VERSION;

:CONNECT SERVER2

SELECT @@VERSION;

:CONNECT SERVER3

SELECT @@VERSION;

I'm sure I'm not the only person that would be surprised to see all three SELECT commands executed against SERVER3 and none executed against SERVER1 or SERVER2. If you think that's odd behavior, here's where to vote: https://connect.microsoft.com/SQLServer/feedback/details/611144/sqlcmd-connect-to-a-different-server-should-be-an-implicit-batch-separator#details

 

6 thoughts on “In SQLCMD mode, should CONNECT be an implicit batch separator?”

  1. Try this :
    :CONNECT SERVER1
    SELECT @@VERSION;
    go
    :CONNECT SERVER2
    SELECT @@VERSION;
    go
    :CONNECT SERVER3
    SELECT @@VERSION;
    go

  2. Hi Duray,
    I know how to fix it but the issue is whether or not the current behavior is sensible. I don't think it is.
    Regards,
    Greg

  3. While parsing and executing are two different things, in SQLCMD mode they both mean the same thing-EXECUTE

  4. BOL does not say much about SQLCMD mode. One need to experiment and verify. It is reasonable to use the batch separator.

  5. The outcome (as it presently works) is both bizarre and unexpected. I think it should be changed.

Leave a Reply

Your email address will not be published. Required fields are marked *