如何仅在一个 ssms 实例中打开多个 .sql 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7123365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open multiple .sql files in only one ssms instance
提问by George_21
I'm DBA with a new server box running Windows Server 2008 Enterprise SP1 with SQL Server 2008 and SQL Server Management Studio.
我是 DBA,有一台运行 Windows Server 2008 Enterprise SP1、SQL Server 2008 和 SQL Server Management Studio 的新服务器。
In my previous box when working in Visual Studio with database solution with lot of .sql files I used to double-click on the .sql files and they were opened in the same SSMS instance (if any already opened). However (even when having exactly the same installation in the new box) I'm now getting a new SSMS instance when double clicking in each sql file. Its really painful one .sql - one SSMS instance so I started my research about that.
在我之前的框中,在 Visual Studio 中使用包含大量 .sql 文件的数据库解决方案时,我曾经双击 .sql 文件,它们在同一个 SSMS 实例中打开(如果已经打开)。但是(即使在新框中具有完全相同的安装),当双击每个 sql 文件时,我现在会获得一个新的 SSMS 实例。它真的很痛苦,一个 .sql - 一个 SSMS 实例,所以我开始了我的研究。
What I've tried till now:
到目前为止我尝试过的:
1) Right click on the .sql file > "Open With" option > "Add" option > "Program Name: C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe" and "Friendly Name: SQL" > "Ok" > "Set as Default". Does NOT work. Still having one sql - one ssms instance.
1)右键单击.sql文件>“打开方式”选项>“添加”选项>“程序名称:C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe ”和“友好名称:SQL”>“确定”>“设为默认值”。不工作。仍然有一个 sql - 一个 ssms 实例。
2) Perfomed Run > regedit > and modify the value data of HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\Command and replace /dde with "%1". DOES NOT WORK
2)Perfomed Run > regedit > 修改HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\Command的值数据,将/dde替换为“%1”。不工作
3) Right click on the .sql file > "Open With" option > "Add" option > "Programe Name: explorer.exe" and "Friendly Name: Explorer" > "Ok" > "Set as default". Does NOT work. When double-clicking on the .sql files Notepad comes with scripts content.
3)右键单击.sql文件>“打开方式”选项>“添加”选项>“程序名称:explorer.exe”和“友好名称:资源管理器”>“确定”>“设置为默认值”。不工作。双击 .sql 文件时,记事本带有脚本内容。
4) Some pages like this
4)有些页面是这样的
http://social.msdn.microsoft.com/Forums/en/sqltools/thread/ac2f39c5-66e5-495c-b7a6-47e743853baf
http://social.msdn.microsoft.com/Forums/en/sqltools/thread/ac2f39c5-66e5-495c-b7a6-47e743853baf
asks to change file association but when opening Windows Explorer > Tools > Folder Options ... I found there is no "File Type" tab. How annoying!
要求更改文件关联,但在打开 Windows 资源管理器 > 工具 > 文件夹选项时...我发现没有“文件类型”选项卡。好烦啊!
Can someone help me on that? My patient it's really running out.
有人可以帮我吗?我的病人真的快用完了。
Thanks in advance
提前致谢
回答by G21
After spending most of my working day looking for the solution I finally found it. Thanks God, I was almost running out with this issue. Hope it helps somebody else!!!.
在花了大部分工作日寻找解决方案后,我终于找到了它。感谢上帝,我几乎用完了这个问题。希望它可以帮助别人!!!。
Update: linked domain expired, so here's what it said:
更新:链接的域已过期,所以它是这样说的:
Considering how integrated Microsoft tools usually are the result is frustrating when you tell Visual Studio to open SQL files using Sql Server Management Studio (SSMS). I really don't like using Visual Studio to edit T-SQL files but in the past, before I discovered this tip, each SQL file I opened would open in a new instance of SSMS. Try it:
- Open a solution which contains SQL files
- Right-click any SQL file and select “Open With…”
- Click “Add”
- Browse to "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe" or if you're running x64 Windows "C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe", then click “OK”
- Click “Set as Default” and then “OK”
Now open multiple SQL files. Each time you'll get a different instance of SSMS opened. What a pain!
NOTE: This entire article applies to SQL 2005, just replace SSMS with SQLWB.
How do you resolve this? Repeat steps 1-3 above, but at step #4 enter the following values:
- Program Name: “explorer.exe”
- Friendly Name: “Windows Explorer”
Repeat step #5 (set as default) above and then click OK. Now, open additional files. They should all open in the same instance of SSMS.
It would seem that Visual Studio issues a command to SSMS.exe which includes the path of the file selected in the solution explorer. It is up to SSMS to check for a new instance, which it doesn't. But when you pass the file name to explorer it gets opened up in the same instance.
QUIRK WARNING!
If SSMS is not already open, the first file you attempt to open (not first time ever, but every time you open an SQL file from Visual Studio and SSMS isn't open yet) SSMS will open, but your file will not. Click the file a 2nd time and it will open the file this time. Don't ask me to explain it it just is (and I have no idea why). Conclusion
The result when you tell Visual Studio that SSMS is the default editor makes sense, but I don't get why it would be different when you tell explorer to open it. Maybe if I were a Windows developer instead of a web developer I would know the answer. But either way, now you know. Enjoy.
考虑到 Microsoft 工具通常是如何集成的,当您告诉 Visual Studio 使用 Sql Server Management Studio (SSMS) 打开 SQL 文件时,结果令人沮丧。我真的不喜欢使用 Visual Studio 来编辑 T-SQL 文件,但在过去,在我发现这个技巧之前,我打开的每个 SQL 文件都会在一个新的 SSMS 实例中打开。尝试一下:
- 打开包含 SQL 文件的解决方案
- 右键单击任何 SQL 文件并选择“打开方式...”
- 点击“添加”
- 浏览到“C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe”或者如果您运行的是 x64 Windows “C:\Program Files (x86)\Microsoft SQL Server \100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe”,然后点击“确定”
- 单击“设置为默认值”,然后单击“确定”
现在打开多个 SQL 文件。每次您都会打开一个不同的 SSMS 实例。多么痛苦!
注意:整篇文章适用于 SQL 2005,只需将 SSMS 替换为 SQLWB。
你如何解决这个问题?重复上面的步骤 1-3,但在步骤 4 中输入以下值:
- 程序名称:“explorer.exe”
- 友好名称:“Windows 资源管理器”
重复上面的第 5 步(设置为默认值),然后单击“确定”。现在,打开其他文件。它们都应该在同一个 SSMS 实例中打开。
Visual Studio 似乎向 SSMS.exe 发出了一个命令,其中包含在解决方案资源管理器中选择的文件的路径。由 SSMS 来检查新实例,但它不会。但是当您将文件名传递给资源管理器时,它会在同一个实例中打开。
怪癖警告!
如果 SSMS 尚未打开,则您尝试打开的第一个文件(不是第一次,但每次从 Visual Studio 打开 SQL 文件并且 SSMS 尚未打开时)将打开 SSMS,但您的文件不会。第二次单击该文件,这次将打开该文件。不要让我解释它只是(我不知道为什么)。结论
当您告诉 Visual Studio SSMS 是默认编辑器时的结果是有道理的,但我不明白为什么当您告诉资源管理器打开它时会有所不同。也许如果我是 Windows 开发人员而不是 Web 开发人员,我就会知道答案。但不管怎样,现在你知道了。享受。
回答by Xavier
I have this problem before, I found there is a simple solution -> just check if your SSMS is under "Run this program as an administrator" option (right click on the shortcut icon -> property -> Compability -> Privilege level). If yes, untick the option and try double click the sql file.
我以前遇到过这个问题,我发现有一个简单的解决方案 -> 只需检查您的 SSMS 是否在“以管理员身份运行此程序”选项下(右键单击快捷方式图标 -> 属性 -> 兼容性 -> 权限级别)。如果是,请取消选中该选项并尝试双击 sql 文件。
Hope this helps.
希望这可以帮助。
回答by Aaron Bertrand
Similar issues have been reported multiple times, but they aren't addressing the issue:
类似的问题已经多次报告,但他们没有解决这个问题:
Did you install Visual Studio (or any Visual Studio components) afterinstalling SQL Server?
安装 SQL Server后是否安装了 Visual Studio(或任何 Visual Studio 组件)?
My guess is that the Connect items will not be fixed - SQL will blame Visual Studio, Visual Studio will blame SQL, and the items will remain open...
我的猜测是 Connect 项目不会被修复——SQL 将归咎于 Visual Studio,Visual Studio 将归咎于 SQL,而这些项目将保持打开状态......
So here is what I suggest: run a repairof SQL Server from Programs and Features and then re-apply the latest service pack of SQL Server 2008 (SP2).
所以这就是我的建议:从“程序和功能”运行SQL Server修复,然后重新应用 SQL Server 2008 (SP2) 的最新服务包。
Also the "File Types" interface was moved from the Tools / Folder Options interface to the Control Panel. Go into Control Panel > Default Programs > "Associate a file type or protocol with a program." However it doesn't seem to have the options here to add command-line options like "%1" or /dde.
“文件类型”界面也从工具/文件夹选项界面移到了控制面板。进入“控制面板”>“默认程序”>“将文件类型或协议与程序关联”。但是,这里似乎没有选项可以添加诸如“%1”或 /dde 之类的命令行选项。
回答by Brian Rudolph
Try adding these reg keys as well, but make sure you put the /dde back in:
也尝试添加这些 reg 键,但请确保将 /dde 放回:
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec]
@="Open(\"%1\")"
For the record, here is my entire export for that section:
作为记录,这是我对该部分的全部导出:
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open]
[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\Command]
@="\"C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\ssms.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"
回答by Marco Alves
I am using SQL Server Management Studio 2012 Express and I have made this to work by pointing "Program" to "explorer.exe"
我正在使用 SQL Server Management Studio 2012 Express,并且通过将“程序”指向“explorer.exe”来使其工作
This is how my register is set up: "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\ssms.exe" /dde
这是我的寄存器的设置方式:“C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\ssms.exe”/dde
at
在
HKEY_CLASSES_ROOT\ssms.sql.11.0\Shell\Open\Command
HKEY_CLASSES_ROOT\ssms.sql.11.0\Shell\Open\Command
回答by user3168424
Go to Tools >> Folder Options >> File Types and apply below settings. It worked for me finally!!! (after half a day search on google).
转到工具>>文件夹选项>>文件类型并应用以下设置。终于对我有用了!!!(在谷歌搜索半天后)。
Click New/Edit (on this window "Confirm open after download" should be check and "Always show extension" should be unchecked)
In next window, make below entries
- Action: Open - Application used to perform action : Your ssms.exe path like "C:\Program Files\Microsoft SQL Server0\Tools\Binn\VSShell\Common7\IDE\Ssms.exe" - Check "Use DDE" check box - DDE Message : Open("%1") - Applicajtion sqlwb.9.0 - DDE Application Not Running: Keep it empty - Topic : system
Regards, Sandeep Gaadhe
单击新建/编辑(在此窗口中,应选中“下载后确认打开”并取消选中“始终显示扩展程序”)
在下一个窗口中,输入以下条目
- Action: Open - Application used to perform action : Your ssms.exe path like "C:\Program Files\Microsoft SQL Server0\Tools\Binn\VSShell\Common7\IDE\Ssms.exe" - Check "Use DDE" check box - DDE Message : Open("%1") - Applicajtion sqlwb.9.0 - DDE Application Not Running: Keep it empty - Topic : system
问候, Sandeep Gaadhe
回答by ko la
From Windows Explorer, one can drag-and-drop selected files (single or multiple) into an SSMS window.
从 Windows 资源管理器中,可以将选定的文件(单个或多个)拖放到 SSMS 窗口中。
回答by Andy
One thing to check is if you have multiple versions of SSMS. If you happen to be working in an older version, double clicking on a file will open the new SSM version. Or whatever the default version is for sql files.
要检查的一件事是您是否有多个版本的 SSMS。如果您碰巧使用的是旧版本,双击文件将打开新的 SSM 版本。或者无论 sql 文件的默认版本是什么。
回答by coldsurfer
I've 2005 & 2008 SSMS installed so I defaulted to the 2005 instance. If I have 2008 ssms open when opening a .sql file from windows explorer it will now open in the existing 2008 ssms (and not try to open a new instance!)
我安装了 2005 和 2008 SSMS,所以我默认使用 2005 实例。如果我在从 Windows 资源管理器打开 .sql 文件时打开了 2008 ssms,它现在将在现有的 2008 ssms 中打开(而不是尝试打开新实例!)