Opening sql files opens new instance of SSMS 18.

Vishal Mittal 36 Reputation points
2020-12-08T10:06:35.6+00:00

46274-ssmsnewinstanceproblem.gifHi, I installed SSMS 18.7.1 in my new laptop and every time I open a new .sql file via double click on it, it opens a new SSMS instance. Its very frustrating. I have repaired SSMS and tried to reinstall again but nothing helped!
But if someone had already installed an old version and after that they are updating to latest SSMS 18.7.1 then this problem is not coming.(Same I tried in my office's PC.)

Can anybody help me in this please.

Thanks.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,834 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 48,976 Reputation points
    2020-12-08T15:37:23.223+00:00

    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. Go to HKCR\.sql.
    3. The default value of this key is the file type. For my machine it is ssms.15.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.

    46287-ssms-singleinstance.txt

    I'm attaching the .reg file that is used on my machine that causes SSMS to open SQL files in the same instance for your reference.

    3 people found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Cameron Usman 35 Reputation points
    2023-05-05T23:14:27.7733333+00:00

    Experimenting with this problem after installing SSMS 19, following some answers here.

    Solution 1:

    Changed HCR\.sql from .sql_auto_file to ssms.sql.19.0 which fixed my issue.

    SSMS OpenWithProgIds

    Solution 2 (possibly better?):

    Changed HCR\.sql\OpenWithProgids default of blank to Open("%1") and reverting HCR\.sql to .sql_auto_file is still working.

    SSMS Open 1

    4 people found this answer helpful.

  2. Ronen Ariely 15,096 Reputation points
    2020-12-08T15:25:51.313+00:00

    Hi,

    If this is a test or development environment then we can do several tests to focus on the real issue. I cannot recommend to do so in production obviously

    (1) Can you preproduce the issue in a new installation on a different machine - I guess not since I did not get any report on this from my clients and they have tens of users. Please confirm if this issue happen in specific machine/s if you can.

    If we can reproduce the issue then we can report it as bug.

    (2) Is this happen for all users or specific user/s?

    Please create a new windows user for the sake of test and check if this issue happen to him (my guess it is not since I guess the issue related to the windows user account but let's confirm it)

    (3) If the answer to test 2 is no, then let's try fix the issue in the user configuration

    Instead of working with the registry directly, let use the more safe approach and use the operating system tool to fix the registry.

    Open Folder options: right click on the file -> select "properties" -> you should see the option "Open with" where you have a button to change the related application which open the file
    46245-image.png
    Click on the button "change" -> select a different application like notepad -> approve and close everything.
    Now repeat the the step and change the application from notepad to SSMS back

    Report if this solve your issue

    2 people found this answer helpful.

  3. Shashank Singh 6,246 Reputation points
    2020-12-08T14:12:15.257+00:00

    Hello,

    That is indeed frustrating please see below link, similar problem faced by someone on stakcexchange forum. It asks to remove registry entries so before doing that PLEASE TAKE REGISTRY BACKUP.

    see how-to-prevent-sql-files-opening-new-instances-of-ssms-17-9-1