21

I'm used to double-clicking *.sql script files to open them in SQL Server Management Studio. I recently upgraded to Win7, and now when I double-click a script file, SSMS opens with an empty environment. I can then use File/Open or File/Recent Files to open my script, but I would much prefer for it to just open whatever I double-clicked on like a normal application would.

Any ideas what's going on?

BTW when I double-click a script from the Solution Explorer in Visual Studio, it does open it automatically just like you would expect.

Dylan Corriveau
  • 2,561
  • 4
  • 29
  • 36
Herb Caudill
  • 50,043
  • 39
  • 124
  • 173

8 Answers8

23

I had the same problem. I don't know what caused it, but I fixed it with a quick Registry hack.

  1. Go to HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\Command
  2. Edit the (Default) value
  3. It should contain something like this: "c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\ssms.exe" /dde
  4. Add "%1" to the end
  5. The final value will be something like this: "c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\ssms.exe" /dde "%1"
Herb Caudill
  • 50,043
  • 39
  • 124
  • 173
Josh Yeager
  • 3,763
  • 1
  • 25
  • 29
  • 2
    FWIW: I had to reinstall SQL and this stopped working for me. Putting the `/dde` back in made it work again. Haven't been able to find out what the `/dde` is for. At any rate this works: `"X:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\SqlWb.exe" /dde "%1"` – Herb Caudill Jun 03 '10 at 15:25
  • Replacing /dde by "%1" would open management studio and the file, but I would also get an error: "There was a problem sending the command to the program". So I added both /dde and "%1" as Herb mentioned and now it works perfect. – joerage Jan 24 '11 at 16:34
  • 1
    Awesome! How in the world do you even start figuring out a solution like this? Great job. – BlackjacketMack May 02 '12 at 15:03
10

In my case the registry key that needed fixing was HKEY_CLASSES_ROOT\.sql

The (Default) had been changed to sql_auto_file... and needed to be ssms.sql.12.0 (for SSMS 2014)... presumably ssms.sql.11.0 for SSMS 2012.

All the other stuff down in the HKEY_CLASSES_ROOT\ssms.sql.12.0 path, that most other solutions tend to refer to, was fine as is.

screenshot of proper reg entry

Beej
  • 794
  • 8
  • 15
  • Same with me on SQL Management Studio 2014: just needed to change HKEY_CLASSES_ROOT\.sql and leave the other values. The original problem I had was slighly different: that sql files would always launch a new SSMS window. – Rory Sep 11 '14 at 13:56
  • ssms.sql.13.0 under HKEY_CLASSES_ROOT\.sql for studio 2016 – Danila Polevshchikov Sep 20 '18 at 08:46
6

I tried all the ideas above (registry entries, etc.) - no luck. What ended up fixing it for me was this:

1. close all SSMS instances.
2. right click on a .sql file and select "Open With..." > "Choose Default Program"
3. Select Notepad
4. Double click on the file - it should open in notepad.
5. close notepad.
6. right click the .sql file again and select "Open With..." > "Choose Default Program" 
7. Select "Sql Management Studio" again.
8. Click the .sql file it should open SSMS
9. Subsequent .sql files should open in the same instance.

Hope this helps :)

Losbear
  • 3,255
  • 1
  • 32
  • 28
4

For SQL Server 2012 the reg key is different:

HKEY_CLASSES_ROOT\ssms.sql.11.0
j0k
  • 22,600
  • 28
  • 79
  • 90
Rohit
  • 41
  • 1
3

It does it on my WinXP box too...

I agree with Josh Yeager, but I went into Control Panel > Folder Options > File Types tab and did it there.

  1. Scroll down to SQL extension
  2. Click Advanced button
  3. Select "Open" from the Actions box
  4. Select "Edit.."

Funny thing is, my "DDE MEssage" box already had a "%1" in there, but it wasn't in the Regedit value. Clicking "OK" out of everything updated the appropriate key(s) and while this is a lot of clicks, it's a better habit to get into than poking around in the registry. Fat-fingered people can get into a lot of trouble in a registry...(that's me, BTW :-D)

Oh, and like Herb Caudill pointed out, the "/dde" needs to be in the regkey but again, using the Folder Options area will handle the appropriate entries.

  • I can't find this in Windows 7 - there's 'Control Panel\All Control Panel Items\Default Programs\Set Associations', but there's not an "Advanced" option anywhere. – Herb Caudill Sep 18 '10 at 15:51
  • @Herb I'm not a Win7 user (yet) so can't confirm, but does this help? http://superuser.com/questions/136133/how-do-i-set-advanced-file-associations-in-windows-7. – Thisisfutile Sep 21 '10 at 14:58
  • I've made an observation after using this fix. I have a shortcut on my desktop to a .SQL file located in my "My Documents" on the file server. Now, when I double-click it, I get a warning, "The following files were specified on the command line: . These files could not be found and will not be loaded." I then click "OK" on the warning and I see the SSMS and a blank query. I can then double-click the shortcut again and it opens in my already opened SSMS. I could do this before the fix but never got the warning message. Not sure what this means, just wanted to share. – Thisisfutile Sep 21 '10 at 15:07
2

Run regedit and go to the following key:

Check to make sure you have tthe correct version. In my case, it is 12.0

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\ssms.sql.12.0\Shell\Open\Command

Edit the default value to add "%1" to the end.

The value should now look like the following: (modify path name to to match the ssms.exe program on your pc)

"c:\Program Files\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\ssms.exe" /dde "%1"

  • This worked for me! Though I'm using SSMS 19 and had to change the `HKEY_CLASSES_ROOT\ssms.sql.19.0\Shell\Open\Command` value to `"C:\Program Files (x86)\Microsoft SQL Server Management Studio 19\Common7\IDE\ssms.exe" /dde "%1"`. – Theodore Brown Jul 26 '23 at 14:18
0

Have you installed the latest relevant SQL Server service pack?

SQL Server 2005 and 2008 need patched on Windows 7. This article is about express but the same "fix" should apply. It's common for each new MS OS.

Generally, you always have your client tools at the same build as your server installs anyway.

gbn
  • 422,506
  • 82
  • 585
  • 676
  • 2
    Whoever downvoted this answer, can you explain why? Give the answerer a change to fix the answer. – A-K Oct 18 '10 at 14:22
0

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell]

[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open]

[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\Command] @="\"c:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\sqlwb.exe\" /dde"

[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec] @="Open(\"%1\")"

[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec\application] @="sqlwb.9.0"

[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec\topic] @="system"

Rich M
  • 377
  • 1
  • 3
  • 12