Opening .sql files in SSMS 2012 as default program and with existing instance
- 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
) Go to
HKEY_CLASSES_ROOT\.sql
and change the default value tossms.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
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
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.
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"
- To change to default entry I utilized an application that displayed the DDE (dynamic data exchange) values. I personally used FileTypesMan.
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.DDE Message: was kept at the SSMS 2008 R2's value I found:
Open("%1")
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 forsqlwb.9.0
that SSMS 2008 R2 entry was showing before I started making my changes in FileTypesMan. I removed the .sql and found that theHKEY_CLASSES_ROOT
had an entry forssms.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.