SQL Management Studio won't open scripts on double-click - sql-server

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.

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"

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.

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 :)

For SQL Server 2012 the reg key is different:
HKEY_CLASSES_ROOT\ssms.sql.11.0

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.

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"

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"

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.

Related

Where is SQLQuery1.sql saved?

Whenever I open up SSMS (SQL Server 2012), I get all of the scripts that I had open in my previous session. This includes both saved queries and any unsaved queries, which are listed as SQLQuery1.sql, SQLQuery2.sql, etc.
I can't seem to find where these "unsaved" queries are being saved. I've checked Documents\SQL Server Management Studio\Backup Files\ (and every other directory in that vicinity). I've also checked the C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\ directory and subdirectories (as best I could). Finally, I did a complete search on my computer for the filename SQLQuery1.sql and it turned up nothing (not that I trust the Windows search function in file explorer).
In case it changes things at all, I also have installed the Redgate SQL Prompt add-on for SSMS.
Any other suggestions?
Thanks!
It's very simple :)
Create new query, then right click on the tab and then choose Open containing folder option.
For example, I got C:\Users\PKuderov\AppData\Local\Temp folder and my SQLQuery4.sql is named ~vs3C67.sql.
So #BenjaminSmith is right but these files have unique temporary names. Until you explicitly save them where you want. It seems they survive ssms reload and you can further filter them by .sql extension and Date Modified.
How about the TEMP folder? Try searching for %TEMP% from your start menu and searching in there.
I got my saved query in the following way.
I made another query and selected to save it.
It popped out the save as dialogue box from where I got all the things which I required.
I copied the file path which was "C:\Users\Shafiq Ur Rehman\Documents\SQL Server Management Studio"

How do I disable The Just in Time Debugger?

Just provisioned a new server running IIS and Server 2012 and SQL Server 2012. I also installed SQL Server Management Studio tool so I can quickly inspect databases without the need to open a remote connection.
When I browse an ASP.NET sites remotely, I get a Just-in-time debgugger exception dialog when an error is encountered in addition to the yellow screen. The dialog stays up on the server and piles up unless I RDP and manually close all the dialog boxes.
The only way to disable this is by removing Visual Studio Shell 2010 (integrated) using the control panel. The side effect is that I can no longer use SSMS.
Most of the available solutions are outdated or don't work. The registry settings are no longer applicable and most articles concerning this issue are old. Microsoft's official documentation is a rat's nest of broken links. Moreover, many users are confusing IE's script debugging dialog with this issue. Although they are related and similar, this specific issue is tied to Visual Studio's runtime environment.
Any ideas?
ASIDE: I can't believe Microsoft has this "feature" on a product that is installed on a production server. I am just floored by the incompetence of a multi-billion dollar corporation. I've seen my question asked since at least since 2005 with no official solution that works. I just have to ask one last time for sanity checking. I want to make sure I'm not the one who is "thick" in the head here.
To disable Just-In-Time debugging by editing the registry
In the Start menu, click Run.
In the Run dialog box, type regedit, then click OK.
In the Registry Editor window, locate and delete the follow registry keys:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\Debugger
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\DbgManagedDebugger
If your computer is running a 64-bit operating system, delete the following registry keys also:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\WindowsNT\CurrentVersion\AeDebug\Debugger
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\DbgManagedDebugger
Take care not to accidentally delete or change any other registry keys.
Instead of deleting it, you can also just (temporarily) rename the AeDebug key for the bitness of your choice to something else, e.g. AeDebug-disable!
For server 2012, IIS, and SSMS 2014 we tried all three registry three deletions and those did not work.
What did work was old school renaming the JIT Debug executable.
Renamed these files.
C:\WINDOWS\system32\vsjitdebugger.exe
C:\Windows\SysWOW64\vsjitdebugger.exe
Renamed this folder
C:\Program Files\Common Files\Microsoft Shared\VS7Debug
As a follow-up to nfox's answer, I've created a registry file that you can simple use instead of searching manually through regedit.exe.
1.) Copy this script to your clipboard:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]
"Debugger"=-
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]
"DbgManagedDebugger"=-
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug]
"Debugger"=-
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework]
"DbgManagedDebugger"=-
2.) Save it to a file with the .reg extension:
E.g. to a file named
C:\Users\<user name>\Desktop\DisableJit.reg
3.) Double click the file
After confirming the appearing message box, the keys are getting deleted.
5.) Alternatively: Download file
If this is too much effort, you can download the registry file from here:
disable-the-just-in-time-debugger-windows-64-bit.reg
disable-the-just-in-time-debugger-windows-64-bit.zip (As a ZIP)
Download and then double-click it.
This tip was simply taken from the MSDN article "Just-In-Time Debugging in Visual Studio".
The syntax on how to delete registry keys via a .reg file was taken from the MSDN KB article "How to add, modify, or delete registry subkeys and values by using a .reg file".
You should be able to disable Jist-In-Time debugging using the Debug options dialog inside Visual Studio. The registry keys are also well documented here.
See:
http://msdn.microsoft.com/en-us/library/5hs4b7a6.aspx
Aside: I think it's not a wise thing to install a management studio on a production server. This is what management workstations are for. Remote connections from a management station can be pre-configured and stored so that it doesn't take much effort. That way you can keep your production environment clean.

Opening .sql files in SSMS 2012 as default program and with existing instance

Installation of SSMS 2012 alongside any other existing SSMS installation, such as SSMS 2008 R2 has a problem with setting the default program for opening .SQL files to the new SSMS 2012 version.
Dragging .sql file to the query window works successfully. However, when a user double clicks on the .sql file a new instance of 2008 R2 can open as the .sql associated entry. Changing with Default Open With makes no difference when doubleclicking on new files. Additionally, altering the command line script for the opening can perhaps achieve changing the .sql to opening in SSMS 2012, but it still causes repeated instances of ssms instead of using the existing instance (causing additional load and memory usage).
Adapted from this post on how to how to fix .sql file not opening with SSMS 2008, you should start by opening up the registry (regedit)
Go to HKEY_CLASSES_ROOT\.sql and change the default value to ssms.sql.11.0 (SSMS 2012 is v11 of the product). This tells your computer the application string it should look for when trying to open files of type .sql
The registry takes that name you just entered and then looks up what to actually go do in another registry setting.
Go HKEY_CLASSES_ROOT\ssms.sql.11.0\Shell\Command and change the default value to:
"C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\ssms.exe" "%1" /dde
Turn your computer off and on again for good measure.
If it still doesn't work for whatever reason. Right click on any SQL file. Go to Properties and click to change the file it opens with. You may have two SQL options available. Try one then the other.
To change to default entry I utilized an application that displayed the DDE (dynamic data exchange) values. I personally used FileTypesMan.
I then changed the command line for SSMS to:
"C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe" /dde "%1"
The reason a new instance is always opened with editing seems to be that windows needs to associate the file with a program so that it can identity if the existing program is running and use this instance. This seems to be achieved by using DDE. /dde indicates that the command line should use DDE. "%1" passes the first string (ssms.exe path) to the DDE protocol for usage as a parameter.
DDE Message: was kept at the SSMS 2008 R2's value I found: Open("%1")
DDE Application: Change the Application to ssms.11.0
Why? This was the difficult part. Where is this found? I could not find a tool for displaying the DDE application name. What I found was when I reviewed the registry editor that sqlwb.sql.9.0 is the entry to open a new .sql file with 2008 R2. This matched the registry entry for sqlwb.9.0 that SSMS 2008 R2 entry was showing before I started making my changes in FileTypesMan. I removed the .sql and found that the HKEY_CLASSES_ROOT had an entry for ssms.sql.11.0 .
= File association now set to new installation, and if SSMS.EXE is open, it should use the existing instance with no additional work.
Tip: To further speed up the initial load if you don't have it open, you can use other command line options on the load. Just go to the RUN dialog and type: ssms.exe -? for a list of startup parameters. I personally use -nosplash to eliminate the splash screen load.
Additionally, I use SSMSBoost, the single greatest tool I've had to help with using SSMS daily (basic code formatting, snippet w/cursor placement, preferred connections setup, full keyboard shortcut programming (along with the option for multiple steps in once shortcut, ie basic macros". Andre and his team are extremely responsive to new ideas in their forum, its very much developers helping improve other developer's life.
For SQL 2014 you can use the following *.reg-file (for 2012 replace the 12 with 11 and for 2016 (I guess) with 13) :
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\sql_auto_file]
#=""
"EditFlags"=hex:00,00,00,00
"FriendlyTypeName"="SQL"
[HKEY_CLASSES_ROOT\sql_auto_file\shell]
[HKEY_CLASSES_ROOT\sql_auto_file\shell\open]
[HKEY_CLASSES_ROOT\sql_auto_file\shell\open\command]
#="\"C:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\ManagementStudio\\Ssms.exe\" /dde \"%1\""
[HKEY_CLASSES_ROOT\sql_auto_file\shell\open\ddeexec]
#="Open(\"%1\")"
[HKEY_CLASSES_ROOT\sql_auto_file\shell\open\ddeexec\Application]
#="ssms.12.0"
[HKEY_CLASSES_ROOT\sql_auto_file\shell\open\ddeexec\Topic]
#="system"
I had this same issue. Using "restore file associations" in ssms 2012 had no effect. I was able to resolve it by right clicking and choosing "open with" -> choose default program. Now I know you've said this didn't work, but there is a trick. Rather than selecting the pre-provided icon for ssms 2012, choose browse and go to c:\program files(x86)\Microsoft SQL server\110\tools\binn\managementStudio\ and click on ssms.exe. Click open, click ok. Once I did this, ssms 2012 was the default, and double clicking more .sql files loads into tabs in the same instance.
Another solution: https://stackoverflow.com/a/24945327/813599
I went looking for a more proper way to link to other Q/A's and couldn't find it after 15 minutes of searching... would love to be educated and will edit this out if so.
I was having a similar but slightly different issue. I wanted to open .sqlplan file in a new tab in SSMS 2014. I tried all of the above but none of them worked.
Looking at the registry, I found that ssms.sql.12.0 has "DdeExec" node, while ssms.sqlplan.12.0 does not.
enter image description here
So I export the "DdeExec" node from ssms.sql.12.0 and rename sql to sqlplan, then import it back in. After that, I was able to open .sqlplan file in a new tab.
Here is the registry file:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\ssms.sqlplan.12.0\Shell\Open\DdeExec]
#="Open(\"%1\")"
[HKEY_CLASSES_ROOT\ssms.sqlplan.12.0\Shell\Open\DdeExec\Application]
#="ssms.12.0"
[HKEY_CLASSES_ROOT\ssms.sqlplan.12.0\Shell\Open\DdeExec\Topic]
#="system"
Management Studio 18:
"C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe" /dde "%1"

Open Alternate Extension in 'Single Instance' of SQL Server Management Studio

I know how to add additional extensions to SQL Server Management Studio, to have them treated just like .sql files. But, when opening them, a new instance of Management Studio is created.
I also see numerous issues posted about double clicking on .SQL files and getting them to open in the existing instance of SQL server. This already works for me.
What doesn't work is the additional extensions I have added. I'm using .PRC. All of the fixes propose changing various registry settings, all which are related to the default .sql extension.
I don't see see how any of these fixes can be applied to make other extensions work or if there is anything else I can do to solve this?
EDIT:
What i've done so far...
Copied over all the same settings from [HKEY_CLASSES_ROOT.sql] to [HKEY_CLASSES_ROOT.prc].
Checked all the settings mentioned in the article on sql server central to fix this issue for .SQL extensions.
Configured SSMS file type .PRC with editing experience "SQL Query Editor".
I even tried creating a batch file to open the file for me:
"c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\ssms.exe" /dde %1
Even the 4th thing I tried opens a new instance, although this is the same call that is configured in the registry for sqlweb.sql.9.0.
I resolved problem of opening PRC file by double click. I simply exported this key from regedit
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.sql
Modified this file to look like this
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.PRC]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.PRC\OpenWithList]
"a"="ssms.exe"
"MRUList"="a"
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.PRC\OpenWithProgids]
"ssms.sql.11.0"=hex(0):
"ssms.sql.12.0"=hex(0):
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.PRC\UserChoice]
"Progid"="ssms.sql.12.0"
And applied it over registry. The original PRC key I backuped and removed from registry before I applied that new keys. Now PRC file is opened by double click on PRC file in opened instance of SSMS.
But highlighting doesn't work still for me :(
You seem to be going through a lot of hassle to deal with your source control system. Have you considered making your source control system recognize a different extension for procedures, tables, views, etc. which will prevent you having to make these registry changes on every developer's computer?
.proc.sql -> stored procedure
.view.sql -> view
.fn.sql -> function
etc. etc. Surely your source control system can handle longer extensions that contain ., and now Management Studio will behave properly with all your file types.

SQL Management Studio Express opening SQL scripts in Notepad

When I go to File > Open > File and select a .sql script, or even when I drag a .sql file into the SQL Management Studio Express window, it opens the script in Notepad which is totally useless when I want to run the script.
Since this is on an external server (Windows 2003 Server), I end up having to disconnect from RDP, disable the local clipboard, re-connect and then copy-paste the script's contents from Textpad in order to run it.
I've checked the options menus but can't see anything relating to Notepad, not even in the "external tools" section. Any ideas why it would be doing this?
Please note: I have checked the file association for SQL scripts and it is set to SQL Management Studio Express.
Ran into this this morning. Turned out to be an encoding issue for me. I opened the script up in UltraEdit and I noticed that it was showing the encoding to be U-DOS instead of DOS. I ran the Unicode to ASCII conversion (also in UltraEdit), saved the file, and now Management Studio is opening up the files correctly.
I encountered this too - thanks NFrank for spotting the issue:
This was caused by opening the script in TextPad and accidentally saving as Unicode. The issue is not related to file associations.
The solution: Open in Notepad (or TextPad) - Save As... and select Encoding: ANSI
UPDATE:
In SQL Management Studio,
Go to File > Open > File,
Highlight a SQL file,
Click the down arrow on the Open button.
Select Open With...
Select SQL Query Editor
Press the Set as Default button.
Matt
The first thing I'd check is to see if the application associated with SQL files on that box is Notepad.

Resources