Windows Phone 7 Developer Launch - Learn More
kick it on DotNetKicks.com   Shout it  

TIP: Open SQL Files in a Visual Studio Project Into the Same Instance of SSMS

Considering how integrated Microsoft tools usually are the result is frustrating when you tell Visual Studio to open SQL files using Sql Server Management Studio (SSMS). I really don't like using Visual Studio to edit T-SQL files but in the past, before I discovered this tip, each SQL file I opened would open in a new instance of SSMS. Try it:

  1. Open a solution which contains SQL files
  2. Right-click any SQL file and select “Open With…”
  3. Click “Add”
  4. Browse to "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe" or if you're running x64 Windows "C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe", then click “OK”
  5. Click “Set as Default” and then “OK”

Now open multiple SQL files. Each time you'll get a different instance of SSMS opened. What a pain!

NOTE: This entire article applies to SQL 2005, just replace SSMS with SQLWB.

How do you resolve this? Repeat steps 1-3 above, but at step #4 enter the following values:

  • Program Name: “explorer.exe”
  • Friendly Name: “Windows Explorer”

Repeat step #5 (set as default) above and then click OK. Now, open additional files. They should all open in the same instance of SSMS.

It would seem that Visual Studio issues a command to SSMS.exe which includes the path of the file selected in the solution explorer. It is up to SSMS to check for a new instance, which it doesn't. But when you pass the file name to explorer it gets opened up in the same instance.

QUIRK WARNING!

If SSMS is not already open, the first file you attempt to open (not first time ever, but every time you open an SQL file from Visual Studio and SSMS isn't open yet) SSMS will open, but your file will not. Click the file a 2nd time and it will open the file this time. Don't ask me to explain it it just is (and I have no idea why).

Conclusion

The result when you tell Visual Studio that SSMS is the default editor makes sense, but I don't get why it would be different when you tell explorer to open it. Maybe if I were a Windows developer instead of a web developer I would know the answer. But either way, now you know. Enjoy.

Tags: , , ,

kick it on DotNetKicks.com   Shout it  

Feedback

# 

Gravatar in my system this not work and open the file using Internet Explorer.
I don't know why, double click in explorer open SSMS but executing the command "explorer.exe file.sql" it open internet explorer 7/16/2009 8:31 AM | noreply@blogger.com (Anonymous)

# 

Gravatar What is your system config? You might need to do a search on issues specific to your OS, SP. 7/16/2009 9:02 AM | noreply@blogger.com (Mark J. Miller)

# 

Gravatar i solved (for now) the internet explorer problem calling a batch that run a vbscript and now it work.

file "runfile.bat" content :
c:\bat\runfile.vbs %1

file "runfile.vbs" content:
Set Wshell = WScript.CreateObject("WScript.Shell")
Wshell.Run WScript.Arguments(0), 1, FALSE 7/16/2009 9:07 AM | noreply@blogger.com (Anonymous)

# 

Gravatar In this condition I use usually next software-retriving data from mdf file,because tool has many facilities and it is free as far as I know,it repair data from corrupted databases in MS SQL Server format (*.mdf extension). 7/27/2009 2:12 PM | noreply@blogger.com (Alex)

# 

Gravatar Alex,

I appreciate you taking the time to comment, but I don't understand - we're not referring to corrupted databases. Did you mean something else? 7/27/2009 2:21 PM | noreply@blogger.com (Mark J. Miller)

# re: TIP: Open SQL Files in a Visual Studio Project Into the Same Instance of SSMS

Gravatar Great tip! This is something that was annoying me for a while! 11/25/2009 1:00 PM | Jon Kragh

# re: TIP: Open SQL Files in a Visual Studio Project Into the Same Instance of SSMS

Gravatar Great tip...interesting it works on some PCs and on others it opens Internet Explorer even thought I have selected "c:\windows\explorer.exe"

SSMS is set as the editor for .sql files and if you click on them in "Windows Explorer" SSMS is opened.

Any thoughts? 2/3/2010 7:03 AM | Mike

# re: TIP: Open SQL Files in a Visual Studio Project Into the Same Instance of SSMS

Gravatar Mike, strange behavior. I haven't a clue why that would happen. I've used it on multiple machines and never seen that happen. 2/3/2010 12:56 PM | MarkJMiller

Comments have been closed on this topic.
 

 

Copyright © Mark J. Miller