14

Synopsis

This is not a new problem and there are several solutions floating around on Internet.

Problem

When you double click on a .sql file, a new instance of SSMS is opened. I did not have this problem until new SQL Server Management Studio (SSMS 17.9.1) was installed.

What I tried

  • This page lists several solutions suggesting registry changes and file associations, and reinstalling SSMS. None worked.
  • This one has almost the same as the previous link. (SO is so much better than those forums.)
  • Registry changes are shown here with excellent screenshots. I added "%1" but that did not make any difference.
  • The suggestion mentioned on SO did not work either.
  • On DBA, it is mostly talking about raised permissions, which is not the case with my situation.

Workarounds

Yes, I know about these workarounds:

  • Ctrl + O
  • Drag .sql files to SSMS

I am not looking for workarounds.

My environment

Even with the new SSMS 17.9.1 (build: 14.0.17289.0), I am still pointing to SQL Server 2016 (13.0.5233.0). Previously, I was using SSMS June 2016 (build: 13.0.15000.23) with the same SQL Server (13.0.5233.0).

Because of permission, I am not running any application as administrator.


SQL Server versions are listed here.

SQL Server Management Studio versions are listed here.

2

5 Answers 5

13

I have encountered this issue after installing SSMS 18 instead of 17.9. Then I have tried solutions from the list above but none worked. Uninstalling SSMS 18 and installing 17.9 again did not work either. I was finally able to resolve this issue with SSMS 18, but I hope it will fix incorrect behavior of SSMS 17 as well. First of all I've uninstalled SSMS, then I've searched through registry to find and remove all meaningful nodes containing info about SSMS or sql_auto_file. I removed the following nodes (don't forget to backup each of them prior to deleting!):

  • HKEY_CLASSES_ROOT.sql
  • HKEY_CLASSES_ROOT\Applications\Ssms.exe
  • HKEY_CLASSES_ROOT\sql_auto_file
  • HKEY_CURRENT_USER\Software\Microsoft\SQL Server Management Studio
  • Removed all records for ssms in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts
  • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.sql
  • HKEY_USERS.DEFAULT\Software\Microsoft\SQL Server Management Studio

Then I've restarted my PC, then installed SSMS 18, then restarted again. After that SSMS opens sql files in existing SSMS instance and explorer has correct file icon assigned (document with small database icon)

3
  • This also solved it for me. A reboot wasn't required. I'm guessing the answers by Steve and Heidi are more specific, and this one is more of a hammer. I've turned the reg-edits into a script: filedropper.com/deletessmskeys
    – Wouter
    Commented Mar 30, 2020 at 8:55
  • In ApplicationAssociationToasts I found sql_auto_file_.sql, ssms.sql.15.0_.sql, and VSCode.sql_.sql to remove. Followed rest of your steps to fix my issue (with SSMS 19 Preview). Thanks
    – cusman
    Commented Jun 25, 2022 at 15:16
  • This worked with SSMS 19 after all other solutions failed, thanks. Now I just need to find a SQL formatter for this new version now that Apex has stopped.
    – Mikustykus
    Commented Dec 8, 2023 at 13:59
5

The post by Alexander G led me to my answer.

I had the same problem whereby opening .sql files from explorer by double clicking them would open a new instance of SSMS, rather than the existing open one. This was a brand new installation of SQL / SSMS on a new laptop so wasn't caused by a conflict with an earlier version.

My standard user account on the laptop is not an Admin, so SSMS was installed using "run as Administrator". It appears that doing it this way populates the correct user specific registry settings in the administrator's account registry rather than mine.

The particular entries that were wrong which seemed to cause the problem were:

  • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts
  • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.sql

I manually created those entries in the HKEY_USERS hive for my user based on the values created for my administrator user, and now my .sql files open in the existing instance of SSMS.

(I think it's something to do with the assocation to sql_auto_file, rather than ssms.sql15.0)

3

I have finally found a solution to this problem. Add the following to your HKCU registry and hopefully it should work:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.sql\OpenWithList]
"a"="ssms.exe"
"MRUList"="a"

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.sql\OpenWithProgids]
"ssms.sql.15.0"=hex(0):
1
  • Second Reg key is binary:[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.sql\OpenWithProgids] "ssms.sql.15.0"=hex(0): Commented May 9, 2020 at 12:58
2

I have a number of SSMS versions installed and always used 2012 because this was the only version that would open all .sql files in the same instance. Recently I had to install 2014 as the old one stopped working with spatial results with my new SQL Server 2014, and what do you know, it had the same problem as all other instances except 2012. I tried that last suggestion about changing the registry in Explorer\FileExt.sql and it did not help. Then I noticed that the key has ssms.exe but not the path to it so interestingly how would it know which of my installed versions to use. Then I completely accidentally noticed that the new instances opening when I double-click on a .sql file are actually version 2012 and not 2014. Then I did the simplest thing I should have done from the start: I right clicked on a .sql file, chose "Properties", "OpensWith" "Change" and browsed to the correct instance I would like to open with, namely 2014. All good now, all files open in the same instance and that is the 2014 even when I start with a double-click on a file, rather than on the shortcut of my 2014 ssms. Hope this helps others.

0

I fixed this by closing Management Studio (v 18.3.1) then double clicking a .sql file in File Explorer which opens SSMS. After that opens I double clicked another .sql and it opened in the same SSMS instance, then did another double click on another .sql and it opened in the same SSMS instance.

In order to see if that 'fixed' it, I closed SSMS, then opened SSMS. Then double clicked two different .sql files and they both opened in the same SSMS instance.

2
  • 4
    This is not a fix, you closed the SSMS that the OP is trying to keep open. Commented Oct 30, 2019 at 17:49
  • it fixed it because now i don't have the problem of ssms starting another instance whenever i dbl click a .sql file. Commented Oct 30, 2019 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.