Opening .sql files in SSMS 2012 as default program and with existing instance

StackOverflow https://stackoverflow.com/questions/14564469

  •  05-03-2022
  •  | 
  •  

Вопрос

Installation of SSMS 2012 alongside any other existing SSMS installation, such as SSMS 2008 R2 has a problem with setting the default program for opening .SQL files to the new SSMS 2012 version.

Dragging .sql file to the query window works successfully. However, when a user double clicks on the .sql file a new instance of 2008 R2 can open as the .sql associated entry. Changing with Default Open With makes no difference when doubleclicking on new files. Additionally, altering the command line script for the opening can perhaps achieve changing the .sql to opening in SSMS 2012, but it still causes repeated instances of ssms instead of using the existing instance (causing additional load and memory usage).

Это было полезно?

Решение 2

  1. To change to default entry I utilized an application that displayed the DDE (dynamic data exchange) values. I personally used FileTypesMan.
  2. I then changed the command line for SSMS to:

    "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe" /dde "%1"
    

    The reason a new instance is always opened with editing seems to be that windows needs to associate the file with a program so that it can identity if the existing program is running and use this instance. This seems to be achieved by using DDE. /dde indicates that the command line should use DDE. "%1" passes the first string (ssms.exe path) to the DDE protocol for usage as a parameter.

  3. DDE Message: was kept at the SSMS 2008 R2's value I found: Open("%1")

  4. DDE Application: Change the Application to ssms.11.0

    Why? This was the difficult part. Where is this found? I could not find a tool for displaying the DDE application name. What I found was when I reviewed the registry editor that sqlwb.sql.9.0 is the entry to open a new .sql file with 2008 R2. This matched the registry entry for sqlwb.9.0 that SSMS 2008 R2 entry was showing before I started making my changes in FileTypesMan. I removed the .sql and found that the HKEY_CLASSES_ROOT had an entry for ssms.sql.11.0 .

= File association now set to new installation, and if SSMS.EXE is open, it should use the existing instance with no additional work.

Tip: To further speed up the initial load if you don't have it open, you can use other command line options on the load. Just go to the RUN dialog and type: ssms.exe -? for a list of startup parameters. I personally use -nosplash to eliminate the splash screen load.

Additionally, I use SSMSBoost, the single greatest tool I've had to help with using SSMS daily (basic code formatting, snippet w/cursor placement, preferred connections setup, full keyboard shortcut programming (along with the option for multiple steps in once shortcut, ie basic macros". Andre and his team are extremely responsive to new ideas in their forum, its very much developers helping improve other developer's life.

Другие советы

  1. Adapted from this post on how to how to fix .sql file not opening with SSMS 2008, you should start by opening up the registry (regedit)
  2. Go to HKEY_CLASSES_ROOT\.sql and change the default value to ssms.sql.11.0 (SSMS 2012 is v11 of the product). This tells your computer the application string it should look for when trying to open files of type .sql

    .sql

  3. The registry takes that name you just entered and then looks up what to actually go do in another registry setting.

    Go HKEY_CLASSES_ROOT\ssms.sql.11.0\Shell\Command and change the default value to:

    "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\ssms.exe" "%1" /dde
    

    ssms.sql.11.0

  4. Turn your computer off and on again for good measure.

    If it still doesn't work for whatever reason. Right click on any SQL file. Go to Properties and click to change the file it opens with. You may have two SQL options available. Try one then the other.

    open with

For SQL 2014 you can use the following *.reg-file (for 2012 replace the 12 with 11 and for 2016 (I guess) with 13) :

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\sql_auto_file]
@=""
"EditFlags"=hex:00,00,00,00
"FriendlyTypeName"="SQL"

[HKEY_CLASSES_ROOT\sql_auto_file\shell]

[HKEY_CLASSES_ROOT\sql_auto_file\shell\open]

[HKEY_CLASSES_ROOT\sql_auto_file\shell\open\command]
@="\"C:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\ManagementStudio\\Ssms.exe\" /dde \"%1\""

[HKEY_CLASSES_ROOT\sql_auto_file\shell\open\ddeexec]
@="Open(\"%1\")"

[HKEY_CLASSES_ROOT\sql_auto_file\shell\open\ddeexec\Application]
@="ssms.12.0"

[HKEY_CLASSES_ROOT\sql_auto_file\shell\open\ddeexec\Topic]
@="system"

I had this same issue. Using "restore file associations" in ssms 2012 had no effect. I was able to resolve it by right clicking and choosing "open with" -> choose default program. Now I know you've said this didn't work, but there is a trick. Rather than selecting the pre-provided icon for ssms 2012, choose browse and go to c:\program files(x86)\Microsoft SQL server\110\tools\binn\managementStudio\ and click on ssms.exe. Click open, click ok. Once I did this, ssms 2012 was the default, and double clicking more .sql files loads into tabs in the same instance.

Another solution: https://stackoverflow.com/a/24945327/813599

I went looking for a more proper way to link to other Q/A's and couldn't find it after 15 minutes of searching... would love to be educated and will edit this out if so.

I was having a similar but slightly different issue. I wanted to open .sqlplan file in a new tab in SSMS 2014. I tried all of the above but none of them worked.

Looking at the registry, I found that ssms.sql.12.0 has "DdeExec" node, while ssms.sqlplan.12.0 does not.

enter image description here

So I export the "DdeExec" node from ssms.sql.12.0 and rename sql to sqlplan, then import it back in. After that, I was able to open .sqlplan file in a new tab.

Here is the registry file: Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\ssms.sqlplan.12.0\Shell\Open\DdeExec]
@="Open(\"%1\")"

[HKEY_CLASSES_ROOT\ssms.sqlplan.12.0\Shell\Open\DdeExec\Application]
@="ssms.12.0"

[HKEY_CLASSES_ROOT\ssms.sqlplan.12.0\Shell\Open\DdeExec\Topic]
@="system"

Management Studio 18:

"C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe" /dde "%1"
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top