views:

1959

answers:

4

I have a few databases that I always use SQL Server Management Studio with. I'd like to be able to create a toolbar button or keyboard shortcut that automatically opens a new query window (in the current SSMS instance) and connects to a given (registered, perhaps) database. That's it. That's all I need. And this ashtray, and the paddle game, and the remote control. That's all I need.

As it is now, I have to expand the Object Explorer, collapse/expand two to eight trees, right-click on my database, and choose "New Query". I see no way to do it, this would probably save me 30-60 seconds a day, which is worth at least one dollar and NINE CENTS.

A: 

You could create a shortcut to launch SQL Server Management studio using command line parameters, as follows:

SQLWB.EXE - launches SQL Server Management Studio from the Command Prompt or Start -> Run text box. Through its switches, you can specify which type of server (-t S, -t A, or -t C for SQL Server, Analysis Server, or SQL Server Mobile Edition, respectively), server name (-S), and database (-d) you want to connect to, provide authentication information, or designate which queries, projects, or solutions to open (-i filename). The defaults (in absence of switches) are defined in the Tools -> Options menu of the SQL Server Management Studio.

[Source]

Ben Hoffstein
Sorry if I wasn't clear--I want this to happen inside one SSMS session using the tabbed interface.
Patrick Szalapski
Gotcha. I added another potential workaround below using AutoHotKey.
Ben Hoffstein
+1  A: 

Have you tried creating a registered server?

Take a look at the "Registered Servers" view (Ctrl-Alt-G). Define a server connection. Set the password, and click the "Remember Password" checkbox if you're not using Windows Authentication. On the "Connection Properties" tab, set your preferred database. Save the server registration.

Now, to connect to that database on that server (assuming you've got the Registered Server pane always visible, as I do), you just need to select that registration node and hit Ctrl-N.

That should save you at least 43 seconds a day.

Michael Petrotta
Yes, I have that. Usually that window isn't shown; plus, this doesn't let me choose a specific database to start in. I usually stick with the object explorer to do this, unless the Registered Servers window is already shown.
Patrick Szalapski
It actually does let you choose a database to start with. See the Connection Properties tab.
Michael Petrotta
Any why not set studio to just show the Registered Server pane all the time? Put it above the Object Explorer; if you've just got a few servers, make it small.
Michael Petrotta
Because I like to auto-hide it, and clicking the tab for it only brings up the registered servers pane, not the object explorer. What I really want is a "registered servers" toolbar, or just a macro that I could assign to a toolbar button.
Patrick Szalapski
Another thing--"registered servers" only lets you work with one starting database. I have two or three (out of hundreds on the server cluster) that I care about; only one of them is my "start" database.
Patrick Szalapski
+1  A: 

This solution is admittedly a hack, but if you can figure out the exact keystrokes needed to accomplish each 'macro', you can use a free tool like AutoHotKey to automate the keystrokes using whatever shortcuts you wish.

Ben Hoffstein
A: 

I haven't read through the whole thing yet, but this article is about creating an add-in for SSMS, which you might be able to do in order to automate what you want.

patmortech