7

After upgrading to SSMS 21, whenever I double-click a .sql file, it opens in a new instance of SSMS instead of using the one that's already running.

I've seen several posts about this issue on older versions of SSMS, where people resolved it by editing the registry, but those solutions don't seem to apply to version 21.

Has anyone else encountered this issue and found a working fix?

I understand that SSMS is designed to mainly open solutions/projects, but in my case, I mostly open .sql files directly to run quick queries against a database, so this behavior is quite inconvenient.

1

3 Answers 3

5

I found a workaround.

First go to HKEY_CLASSES_ROOT\.sql\OpenWithProgids registry key. There is string value started with SSMS.sql. eg. "SSMS.sql.e723483f" is my case.

enter image description here

Then go to the key HKEY_CLASSES_ROOT\<value>\shell\Open\ddeexec\Application where <value> corresponds to the string value from the previous key (in my case. HKEY_CLASSES_ROOT\SSMS.sql.e723483f\shell\Open\ddeexec\Application).

There change (Default) string value from "SSMS.21.1" to "SSMS.21.0".

Sign up to request clarification or add additional context in comments.

3 Comments

I wonder if this workaround will break with SSMS 21.2 comes out.
It works on my computer too. Hope this does not change.
Well, SSMS 21.2 is now out; has this broken the fix?
3

I have this issue on both my desktop and laptop in 21.1.3 and none of the solutions for previous major versions of SSMS worked for me either.

Looks like the dev team are aware of the issue at least:

https://developercommunity.visualstudio.com/t/SSMS:-SQL-files-opening-new-instances-of/10858946?zu=


The fix linked above has been released in version 21.3.6.

1 Comment

Looks like this has been released in version 21.3.6.
0

I would still try the solution in this post you've mentioned Where they state:

"Right click the .sql file within Visual Studio, then click "open with", then click "add..." in "Open with" dialog. In the "add program" dialog type "explorer.exe" into the program name field and somehting into "firendly name" field e.g. "with explorer", then click ok. Then select "with exlorer" in "Open with" dialog and click "set as default". Now VS will open .sql files with explorer wich will in its turn call SSMS."

And also try the registry change

HKEY_CLASSES_ROOT\sqlwb.sql.[your_version_here]\Shell\Open\Command, replace /dde with %1

Otherwise there is this post where they write pretty much the same (you need to modify the registry):

DDE is used to allow the shell to open multiple .SQL files in the same instance. You need to modify the registry to get that to work.

NOTE: The shell associations are stored under HKCR however you can override the global settings on a per-user basis. These are stored under HKCU\Classes. Ensure you don't have an overridden version when making changes to the registry as that will cause the global settings to be ignored.

  1. Open Regedit.

  2. The shell first looks up the file extension in the registry to get the file type. This allows multiple file extensions to map to the same commands. NOTE: You would need to do this for each file extension you want to adjust the behavior of. Get to HKCR\.sql.

  3. The default value of this key is the file type. E.g: ssms.21.0.

  4. Go to the file type key under HKCR. This is where the shell gets the commands for the context menu. They reside under the shell key. You may see one or more verbs such as edit and open. You'll want to adjust the command for the default verb the shell uses.

  5. Go to the command key. This is the command that the shell runs when you select the verb. The key here is that it must use DDE. On my machine it looks like this: "<path>\ssms.exe" /dde. The double quotes are critical to allow for long file names.

  6. For DDE the shell then needs to know how to start up the DDE server. For that it goes to the ddeExec key.

  7. This key has a default value that specifies the DDE command to use. For SQL it is Open("%1"). This tells SSMS to open the given file, again the double quotes are critical. Given that DDE command the current SSMS instance will open the given file in the existing instance.

The reg related file (Note change sql.21 and Microsoft SQL Server Management Studio 21 to any matching version of your actual SSMS instance):

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\ssms.sql.21.0]
@="Microsoft SQL Server Query File"

[HKEY_CLASSES_ROOT\ssms.sql.21.0\DefaultIcon]
@="C:\\Program Files (x86)\\Microsoft SQL Server Management Studio 18\\Common7\\IDE\\ssms.exe,-10000"

[HKEY_CLASSES_ROOT\ssms.sql.21.0\Shell]

[HKEY_CLASSES_ROOT\ssms.sql.21.0\Shell\Open]

[HKEY_CLASSES_ROOT\ssms.sql.21.0\Shell\Open\Command]
@="\"C:\\Program Files (x86)\\Microsoft SQL Server Management Studio 21\\Common7\\IDE\\ssms.exe\" /dde"

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

[HKEY_CLASSES_ROOT\ssms.sql.21.0\Shell\Open\DdeExec\Application]
@="ssms.15.0"

[HKEY_CLASSES_ROOT\ssms.sql.21.0\Shell\Open\DdeExec\Topic]
@="system"

6 Comments

HKEY_CLASSES_ROOT\sqlwb.sql.9.0 doesn't even exist on my machine, let alone the rest of the path (Note, I've not migrated to SSMS 21 yet, I'm still using SSMS 20, but I do have SSMS 21 installed).
Unfortunatelly I don't have it installed on my machine, as I am not on my work pc atm. But usually I search for a path that is close to the one mentioned It would be "HKEY_CLASSES_ROOT\sqlwb.sql.xx" or something similar. Microsoft like to mess with the Registery but usually the updated registery name is never really far
I updated the answer. Please take a look
Unfortunately, none of these solutions worked for me. Additionally, the registry structure for version 21 appears to be somewhat different: the default registry path looks something like HKEY_CLASSES_ROOT\SSMS.sql.d7f42986. I tried adding the same registry entries under this path, but without success. It seems that version 21 differs significantly from previous versions.
It doesn't surprise me that the registry entries are (entirely) different for SSMS 21, @Gioele ; the release is very different to prior releases.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.