How to open multiple .sql files in only one ssms instance

我们两清 提交于 2019-11-29 09:05:21
G21

After spending most of my working day looking for the solution I finally found it. Thanks God, I was almost running out with this issue. Hope it helps somebody else!!!.

Update: linked domain expired, so here's what it said:

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.

I have this problem before, I found there is a simple solution -> just check if your SSMS is under "Run this program as an administrator" option (right click on the shortcut icon -> property -> Compability -> Privilege level). If yes, untick the option and try double click the sql file.

Hope this helps.

Similar issues have been reported multiple times, but they aren't addressing the issue:

http://connect.microsoft.com/VisualStudio/feedback/details/105575/multiple-instances-of-sqlwb-exe-when-management-studio-set-as-default-editor

http://connect.microsoft.com/SQLServer/feedback/details/622181/multiple-ssms-open-for-seperate-sql-files

http://connect.microsoft.com/SQLServer/feedback/details/680761/a-new-instance-of-ssms-is-opened-when-trying-to-open-a-tsql-file-even-when-an-instance-is-running

Did you install Visual Studio (or any Visual Studio components) after installing SQL Server?

My guess is that the Connect items will not be fixed - SQL will blame Visual Studio, Visual Studio will blame SQL, and the items will remain open...

So here is what I suggest: run a repair of SQL Server from Programs and Features and then re-apply the latest service pack of SQL Server 2008 (SP2).

Also the "File Types" interface was moved from the Tools / Folder Options interface to the Control Panel. Go into Control Panel > Default Programs > "Associate a file type or protocol with a program." However it doesn't seem to have the options here to add command-line options like "%1" or /dde.

Brian Rudolph

Try adding these reg keys as well, but make sure you put the /dde back in:

[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec]
@="Open(\"%1\")"

For the record, here is my entire export for that section:

[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open]

[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\Command]
@="\"C:\\Program Files (x86)\\Microsoft SQL Server\\100\\Tools\\Binn\\VSShell\\Common7\\IDE\\ssms.exe\" /dde"

[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec]
@="Open(\"%1\")"

[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec\application]
@="sqlwb.9.0"

[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec\topic]
@="system"

Go to Tools >> Folder Options >> File Types and apply below settings. It worked for me finally!!! (after half a day search on google).

  1. Click New/Edit (on this window "Confirm open after download" should be check and "Always show extension" should be unchecked)

  2. In next window, make below entries

       - Action: Open
       - Application used to perform action : Your ssms.exe path like "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"
       - Check "Use DDE" check box
       - DDE Message : Open("%1")
       - Applicajtion sqlwb.9.0
       - DDE Application Not Running: Keep it empty
       - Topic : system
    

    Regards, Sandeep Gaadhe

I am using SQL Server Management Studio 2012 Express and I have made this to work by pointing "Program" to "explorer.exe"

This is how my register is set up: "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\ssms.exe" /dde

at

HKEY_CLASSES_ROOT\ssms.sql.11.0\Shell\Open\Command

I've 2005 & 2008 SSMS installed so I defaulted to the 2005 instance. If I have 2008 ssms open when opening a .sql file from windows explorer it will now open in the existing 2008 ssms (and not try to open a new instance!)

From Windows Explorer, one can drag-and-drop selected files (single or multiple) into an SSMS window.

One thing to check is if you have multiple versions of SSMS. If you happen to be working in an older version, double clicking on a file will open the new SSM version. Or whatever the default version is for sql files.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!