如何仅在一个 ssms 实例中打开多个 .sql 文件

发布于 2024-11-30 11:14:28 字数 1141 浏览 3 评论 0 原文

我是 DBA,拥有一台运行 Windows Server 2008 Enterprise SP1、SQL Server 2008 和 SQL Server Management Studio 的新服务器。

在我之前的框中,当在 Visual Studio 中使用包含大量 .sql 文件的数据库解决方案工作时,我常常双击 .sql 文件,然后在同一个 SSMS 实例中打开它们(如果已打开)。但是(即使在新框中具有完全相同的安装)我现在在双击每个 sql 文件时都会获得一个新的 SSMS 实例。一个 .sql - 一个 SSMS 实例真的很痛苦,所以我开始对此进行研究。

到目前为止我已经尝试过:

1)右键单击 .sql 文件> “打开方式”选项> “添加”选项> “程序名称:C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe”和“友好名称:SQL”> “好的”> “设置为默认值”。不起作用。仍然有一个 sql - 一个 ssms 实例。

2)执行运行>注册表编辑器>修改HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\Command的值数据,将/dde替换为“%1”。不起作用

3) 右键单击​​ .sql 文件 > “打开方式”选项> “添加”选项> “程序名称:explorer.exe”和“友好名称:Explorer”> “好的”> “设置为默认值”。不起作用。双击 .sql 文件时,记事本会附带脚本内容。

4)有些页面像这样

http://social.msdn.microsoft.com/Forums/en/sqltools/thread/ac2f39c5-66e5-495c-b7a6-47e743853baf

要求更改文件关联,但在打开 Windows 资源管理器时 > ;工具>文件夹选项...我发现没有“文件类型”选项卡。真烦人!

有人可以帮我吗?我的病人,它真的快用完了。

提前致谢

I'm DBA with a new server box running Windows Server 2008 Enterprise SP1 with SQL Server 2008 and 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.

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.

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

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.

4) Some pages like this

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!

Can someone help me on that? My patient it's really running out.

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

孤星 2024-12-07 11:14:28

在花了我大部分工作日寻找解决方案后,我终于找到了。感谢上帝,我几乎快要解决这个问题了。希望它对其他人有帮助!

更新:链接域已过期,所以内容如下:

考虑到 Microsoft 工具通常的集成程度,结果是
当您告诉 Visual Studio 使用 Sql 打开 SQL 文件时,令人沮丧
服务器管理工​​作室(SSMS)。我真的不喜欢使用视觉
Studio 编辑 T-SQL 文件,但在过去,在我发现这一点之前
提示,我打开的每个 SQL 文件都会在 SSMS 的新实例中打开。尝试
它:

  1. 打开包含 SQL 文件的解决方案
  2. 右键单击任意 SQL 文件并选择“打开方式...”
  3. 点击“添加”
  4. 浏览到“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”,然后单击“确定”
  5. 点击“设置为默认值”,然后点击“确定”

现在打开多个 SQL 文件。每次你都会得到一个不同的实例
SSMS 已打开。好痛苦啊!

注意:整篇文章适用于 SQL 2005,只需将 SSMS 替换为
SQLWB。

你如何解决这个问题?重复上面的步骤 1-3,但在步骤 #4 输入
以下值:

  • 程序名称:“explorer.exe”
  • 友好名称:“Windows 资源管理器”

重复上面的第 5 步(设置为默认值),然后单击“确定”。现在,打开
附加文件。它们应该全部在同一个 SSMS 实例中打开。

Visual Studio 似乎向 SSMS.exe 发出了一个命令,其中
包括在解决方案资源管理器中选择的文件的路径。这是
由 SSMS 检查是否有新实例,但它没有。但是当你
将文件名传递给资源管理器,它会在同一实例中打开。

奇怪的警告!

如果 SSMS 尚未打开,则您尝试打开的第一个文件(不是
有史以来第一次,但每次您从 Visual 打开 SQL 文件时
Studio 和 SSMS 尚未打开)SSMS 将打开,但您的文件将打开
不是。第二次单击该文件,这次将打开该文件。
不要让我解释它就是这样(我不知道为什么)。
结论

告诉 Visual Studio SSMS 是默认编辑器时的结果
有道理,但我不明白为什么当你告诉时情况会有所不同
资源管理器打开它。也许如果我是一名 Windows 开发人员而不是
网络开发人员我想知道答案。但无论如何,现在你知道了。
享受吧。

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:

  1. Open a solution which contains SQL files
  2. Right-click any SQL file and select “Open With…”
  3. Click “Add”
  4. 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”
  5. 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.

著墨染雨君画夕 2024-12-07 11:14:28

我以前也遇到过这个问题,我发现有一个简单的解决方案->只需检查您的 SSMS 是否位于“以管理员身份运行此程序”选项下(右键单击快捷方式图标 -> 属性 -> 兼容性 -> 权限级别)。如果是,请取消选中该选项并尝试双击该 sql 文件。

希望这有帮助。

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.

Hope this helps.

清醇 2024-12-07 11:14:28

我的多个 SSMS 实例版本 19 的问题已通过将 HKEY_CLASSES_ROOT.sql 默认键更改为

在此处输入图像描述

My issue with multiple SSMS instances version 19 was fixed by changing HKEY_CLASSES_ROOT.sql Default key to

enter image description here

橘香 2024-12-07 11:14:28

类似的问题已多次报告,但它们没有解决该问题(删除了链接,因为 Microsoft 不假思索地删除了 Connect):

安装 SQL Server 后是否安装了 Visual Studio(或任何 Visual Studio 组件)?

我的猜测是,连接项目不会被修复 - SQL 将责怪 Visual Studio,Visual Studio 将责怪 SQL,并且这些项目将保持打开状态...

所以这是我的建议:运行修复从程序和功能中删除 SQL Server,然后重新应用 SQL Server 2008 (SP2) 的最新 Service Pack。

此外,“文件类型”界面也从“工具/文件夹选项”界面移至“控制面板”。进入控制面板>默认程序> “将文件类型或协议与程序关联起来。”然而,这里似乎没有添加命令行选项(如“%1”或/dde)的选项。

Similar issues have been reported multiple times, but they aren't addressing the issue (removed links because Microsoft erased Connect without much thought):

Did you install Visual Studio (or any Visual Studio components) after installing SQL Server?

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

So here is what I suggest: run a repair of SQL Server from Programs and Features and then re-apply the latest service pack of 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.

放我走吧 2024-12-07 11:14:28

也尝试添加这些注册表项,但请确保将 /dde 放回:

[HKEY_CLASSES_ROOT\sqlwb.sql.9.0\Shell\Open\ddeexec]
@="Open(\"%1\")"

为了记录,这是我对该部分的完整导出:

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

Try adding these reg keys as well, but make sure you put the /dde back in:

[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"
不甘平庸 2024-12-07 11:14:28

转到工具>>文件夹选项>>文件类型并应用以下设置。它终于对我有用了! (在谷歌搜索了半天后)。

  1. 单击新建/编辑(在此窗口中,应选中“下载后确认打开”,并取消选中“始终显示扩展名”)

  2. 在下一个窗口中,进行以下输入

     - 操作:打开
       - 用于执行操作的应用程序:您的 ssms.exe 路径,例如“C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe”
       - 选中“使用DDE”复选框
       - DDE 消息:打开(“%1”)
       - 应用程序sqlwb.9.0
       - DDE 应用程序未运行:将其保留为空
       - 主题:系统
    

    问候,
    Sandeep Gaadhe

Go to Tools >> Folder Options >> File Types and apply below settings. It worked for me finally!!! (after half a day search on google).

  1. Click New/Edit (on this window "Confirm open after download" should be check and "Always show extension" should be unchecked)

  2. In next window, make below entries

       - Action: Open
       - Application used to perform action : Your ssms.exe path like "C:\Program Files\Microsoft SQL Server\100\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

倥絔 2024-12-07 11:14:28

我正在使用 SQL Server Management Studio 2012 Express,我通过将“Program”指向“explorer.exe”来使其工作,

这就是我的寄存器的设置方式:“C:\Program Files (x86)\Microsoft SQL Server\ 110\Tools\Binn\ManagementStudio\ssms.exe" /dde

位于

HKEY_CLASSES_ROOT\ssms.sql.11.0\Shell\Open\Command

I am using SQL Server Management Studio 2012 Express and I have made this to work by pointing "Program" to "explorer.exe"

This is how my register is set up: "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

陌生 2024-12-07 11:14:28

我已经 2005 &安装了 2008 SSMS,因此我默认使用 2005 实例。如果我在从 Windows 资源管理器打开 .sql 文件时打开了 2008 ssms,它将在现有的 2008 ssms 中打开(而不是尝试打开新实例!)

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

调妓 2024-12-07 11:14:28

从 Windows 资源管理器中,可以将选定的文件(单个或多个)拖放到 SSMS 窗口中。

From Windows Explorer, one can drag-and-drop selected files (single or multiple) into an SSMS window.

农村范ル 2024-12-07 11:14:28

要检查的一件事是您是否有多个版本的 SSMS。如果您碰巧使用的是旧版本,双击文件将打开新的 SSM 版本。或者无论 sql 文件的默认版本是什么。

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.

花间憩 2024-12-07 11:14:28

对于希望 SSMS 始终以管理员权限打开的用户的快速说明。

  • 在开始菜单中找到 SSMS。 右键单击>更多>打开文件位置
  • 在 Windows 资源管理器中看到 Microsoft SQL Server Management Studio* 的快捷方式后,右键单击>打开文件位置
  • 然后右键单击 Ssms.exe>“兼容性疑难解答”
  • 然后点击程序疑难解答
  • 勾选程序需要额外权限,然后点击下一步
  • 现在它会强制您按测试程序...
  • 然后按下一步,然后按是,保存此程序的这些设置

Arvo Bowen Jan 20 20 年 3 月 30 日 15:27

效果非常好。

A quick note for users who want to have SSMS always open with Administrator privileges.

  • Find SSMS in your start menu. Right-click>More>Open File Location.
  • Once you see the shortcut to Microsoft SQL Server Management Studio * in Windows Explorer, Right-click>Open File Location.
  • Then Right-click on Ssms.exe>Troubleshoot compatibility.
  • Then click Troubleshoot program.
  • Put a tick by The program requires additional permissions then hit Next.
  • Now it forces you to press Test the program....
  • Then press Next and then Yes, save these settings for this program.

Arvo Bowen Jan 30 '20 at 15:27

This work perfectly.

酷遇一生 2024-12-07 11:14:28

我知道这是一篇相当老的帖子,有很多不同的答案和可能的解决方案。但我认为这是一个新的(至少对于SO来说)。

我突然开始出现这种行为(即每个新文件都会在新会话中打开)并且无法弄清楚原因。事实证明,这是因为在我的 SSMS 会话中,我进行了一次公开对话,但该对话已落入后台。

当我关闭对话时,新文件开始在我原来的会话中打开 /facepalm

也许每个人都已经知道这一点,但以防万一它可以节省任何人 20 分钟!

I know this is quite an old post and there are loads of different answers with possible solutions. But here's one I think is new (at least to SO).

I suddenly starting getting this behaviour (i.e. each new file would open in a new session) and couldn't figure out why. Turns out it was because in my SSMS session I had an open dialogue which had dropped into the background.

A soon as I closed the dialogue, new files started opening in my original session /facepalm

Maybe everyone knows this already but just in case it saves anyone 20 mins!

花落人断肠 2024-12-07 11:14:28

老问题,但就我而言,在最近打开的 .sql 文件的应用程序列表中,同时列出了“SQL Server Management Studio”和“SSMS 18”,这导致它打开一个新实例。

我选择了“选择另一个应用程序”,选择了“SQL Server Management Studio”,然后选中了“始终使用此应用程序打开 .sql 文件”。问题解决了。

Old question, but in my case, in the recent list of apps to open for .sql files, there were both "SQL Server Management Studio" and "SSMS 18" listed, which was causing it to open a new instance.

I selected "Choose another app", selected "SQL Server management Studio", and checked "Always use this app to open .sql files." Problem solved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文