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.

3
  • 1
    I have Windows 7 and seing the same behavior with Windows 7 when SQL Management Studio is not already open. When it is open already, the sql file opens correctly. Commented Nov 13, 2009 at 1:57
  • @JoeRage - Thanks, I checked and that's the case with me as well. Commented Nov 13, 2009 at 2:45
  • FWIW - dragging and dropping the script on a shortcut to SSMS opens it as expected. Commented Nov 13, 2009 at 2:46

8 Answers 8

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"
Sign up to request clarification or add additional context in comments.

3 Comments

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"
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.
Awesome! How in the world do you even start figuring out a solution like this? Great job.
13

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

3 Comments

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.
ssms.sql.13.0 under HKEY_CLASSES_ROOT\.sql for studio 2016
For SSMS 20 set the value to ssms.sql.20.0
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 :)

3 Comments

Did not help me. Wish it had!
King of answers, simple and effective
all the other registry hacks didn't work. This simple few steps sorted it.
4

For SQL Server 2012 the reg key is different:

HKEY_CLASSES_ROOT\ssms.sql.11.0 

1 Comment

Follow the accepted answer using this path for 2012.
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.

3 Comments

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 I'm not a Win7 user (yet) so can't confirm, but does this help? superuser.com/questions/136133/….
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: <path to file on server>. 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.
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"

1 Comment

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".
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"

Comments

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.

1 Comment

Whoever downvoted this answer, can you explain why? Give the answerer a change to fix the answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.