views:

769

answers:

5

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.

A: 

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
Whoever downvoted this answer, can you explain why? Give the answerer a change to fix the answer.
AlexKuznetsov
+1  A: 

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. Remove /dde from the end and add "%1"
  5. The final value will be something like this: "c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\ssms.exe" "%1"
Josh Yeager
Beautiful - that does the trick. Thanks!
Herb Caudill
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
A: 

The combination on my Dell D620 notebook... Windows 7 x32 Ultimate and SQL Server 2008 x32 Standard Edition with Service Pack 1 (10.0.2531.0). Same issue as above. Was able to locate the registry entry referenced by Josh Yeager in his solution and modified with a "%1" after the /dde text in the command line. This now worked as would be expected -- double click on a *.sql from the file explorer and SSMS opens with the script already loaded. Thanks Josh...

Eric Skidmore
+1  A: 

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.

Thisisfutile
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
@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
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.
Thisisfutile
A: 

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