Connect to a server from (pseudo?) tsql
buckley
Posts: 69 New member
Hello Support,
When I learned about sqlcmd mode in ssms I got my hopes up that I could switch in my tsql from server. Something that I do many times a minute :
:CONNECT ServerX
It turns out that ssms opens and closes the connection after it ran. Sql Prompt isn't giving intellisense for databases in ServerX as well I think.
Is it technically possible for prompt to support a syntax and switch to another server and just stay with the keyboard+intellisense?
Kr, Tom
When I learned about sqlcmd mode in ssms I got my hopes up that I could switch in my tsql from server. Something that I do many times a minute :
:CONNECT ServerX
It turns out that ssms opens and closes the connection after it ran. Sql Prompt isn't giving intellisense for databases in ServerX as well I think.
Is it technically possible for prompt to support a syntax and switch to another server and just stay with the keyboard+intellisense?
Kr, Tom
Comments
I just had a look into if this is technically possible in SQL Prompt and I think it would be. I guess it'd work similarly to how Prompt handles a USE statement to start suggesting objects from a different database.
Unfortunately it does look like it'd be a bit more complicated than the USE statement logic to implement (especially if you happen to switch to a different server version).
As it'd be a reasonable amount of work for us to implement, the best place to log it would be on our UserVoice forum which we use to help track and prioritise new features (plus you'll get notified when we have a new build ready, along with anyone else who's also interested).
Thanks,
Aaron.
The main reason for asking this feature is to quickly switch between servers from the keyboard
For example, embedding prompt commands in comment like the following
--Connect ServerX
Once "executed" (in quotes as it is a comment but prompt understands) it will switch to that server
That's it.
Building further on this the feature can be expand to support intellisense after a "prompt command".
So that it statically knows by parsing the text that the commands after the prompt command are for another server.
This expansion is a nice to have. I was mainly looking for a way to switch between servers as no other extension that I know offers it and I still have to go through the "change connection" button/menu in ssms.
Makes sense? I will formulate it as a uservoice item as well but would like to use this forum to align our understanding of what the feature is and why it can be useful.
Kr, Tom
It's not quite as slick as uncommenting a line to switch servers but adding a keyboard shortcut to the change connection command might get you pretty close to your goal?
Using :CONNECT to switch makes complete sense to me from a usability point of view - if it was a simple change I would have made it for you already As I mentioned before, Prompt does something similar with statically parsing USE statements to start offering suggestions from different databases on the same server.
Thanks!
Aaron.
I'll give it another go
It would be a nice feature though not just to quickly switch servers but to have a script that can command multiple servers, fe:
===
Select ...
--switch ServerX
Select ...
--switch ServerY
Select ...
--switch ServerZ
===
Did you notice the :CONNECT directive once executed switches back to the original server? So recuperating this directive is not a way to switch a server unless Prompt changes the semantics if it is executed on its own for example.
"
You've used all your votes and won't be able to post a new idea, but you can still search and comment on existing ideas.
"
This was the item I was trying to create on the UserVoice forum
Subject: Switch to a server from code
Body:
I propose a feature where I can type a server and switch to it.
Either by executing the line I just typed or that Prompt, after observing my keystrokes, does automatically
Example,
===
Select x ...
--switch ServerX
Select x ...
===
If I execute the second line the connection would be to ServerX
Note 1
In SqlCmd mode we have the :CONNECT directive but its not permanent. SSMS switches to the new server and immediately switches to the old.
Maybe this directive can be used if there is a way to not mess with the original semantics of putting ssms in sqlcmd mode
Originating forum thread
viewtopic.php?f=169&t=79455
I've created a new UserVoice idea for you here: https://redgate.uservoice.com/forums/94 ... -from-code
You should be able to reallocate your votes from other ideas if you want to support this idea instead.