问题
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.
回答1:
I had the same problem. I don't know what caused it, but I fixed it with a quick Registry hack.
- Go to HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\Command
- Edit the (Default) value
- It should contain something like this:
"c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\ssms.exe" /dde
- Add
"%1"
to the end - 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"
回答2:
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.

回答3:
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 :)
回答4:
For SQL Server 2012 the reg key is different:
HKEY_CLASSES_ROOT\ssms.sql.11.0
回答5:
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.
- Scroll down to SQL extension
- Click Advanced button
- Select "Open" from the Actions box
- 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.
回答6:
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"
回答7:
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.
回答8:
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"
来源:https://stackoverflow.com/questions/1726577/sql-management-studio-wont-open-scripts-on-double-click