views:

1182

answers:

5

I'm using visual studio's external tools to open .sql scripts in Sql Server Management Studio (SSMS). The problem is, each time I use the external tools command to open a .sql file from visual studio, it opens a new instance of SSMS.

Visual Studio has a switch /Edit that will do this, is there one for SQL Server Management Studio?

+1  A: 

I don't think the problem is with Visual Studio external tool command. Look at SSMS command line options - maybe there is a way to force reusing existing SSMS instance.

Juozas Kontvainis
Looks to me like there isn't.
jcollum
A: 

If you associate that file extension with Visual Studio, then VS should open it.

If you're finding that VS starts a new instance every time, then you need to specify the /edit command line option.

Take a look at http://stevedunns.blogspot.com/2009/03/programs-that-launch-or-should-launch.html for more information.

Steve Dunn
That's a cmd switch for visual studio, but not for sql server management studio. See devenv.exe /?I'm looking for that exact functionality, but for SSMS.
TheImirOfGroofunkistan
A: 

The correct answer is no. The SSMS has a limited set of options, and although it uses the VS framework, does not support the edit command. This could be an interesting feature to add.

I am assuming you need to open these scripts in SSMS to be able to run them as well, otherwise I would suggest pointing them to Visual Studio directly since it does support syntax highlighting. However it will not solve your problem.

Diago
+6  A: 

Choose to open the file with Explorer[1] instead of SSMS. That way the system will search for any existing instances of SSMS first.

[1] %windir%\explorer.exe

KevinT
this worked great, thanks for the response.
TheImirOfGroofunkistan
This works just as if you had double-clicked your sql file from Windows Explorer (or typed the path in the Run box). Works perfect, thanks!
sliderhouserules
Unfortunately double clicking on the file opens a new instance of SSMS.exe for me. Could be because I'm in XP (not my decision!). So, sadly, this didn't work for me.
jcollum
This also works for specifying a DDL editor in Enterprise Architect. Thanks!
Cory Larson
A: 

Hi, The following works for me ( I am SQL Server 2008 though) :

So the real answer I quess is to use cmdow

Edit: After more testing I realized the following : First open the files with connenction with: ( remove any enters while copying, this is one liner )

"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\
Common7\IDE\Ssms.exe" "C:\Users\yordgeor\Desktop\Trigger.sql"
"C:\Users\yordgeor\Desktop\Trigger1.sql" -S ysg -d poc_dev -E -nosplash

In this example it opens two files ( but you could open less of course ; ) after which , No matter how many times I run

cmdow /Run "C:\Users\yordgeor\Desktop\Trigger1.sql" 
cmdow /Run "C:\Users\yordgeor\Desktop\Trigger2.sql" 
cmdow /Run "C:\Users\yordgeor\Desktop\Trigger3.sql"

it opens the same instance of the Microsoft Sql Server Management Studio with the same connection

you could open at once at the command line many files , but I quess you asked for the upper answer.

So you could find the path to the Ssms.exe by: cd %ProgramFiles%

dir *ssms.exe /s /b

so the syntax of the command is: pathToTheExe pathToFile1 pathToFile2 -S serverName -d DatabaseToConnectTo -E (toUseWindowsAuthentication) -nosplash

After 20 seconds of googling I cheated from here:

YordanGeorgiev