简体   繁体   English

在 SQL Server Management Studio(2005 或更高版本)中连接不同的 Windows 用户

[英]Connect different Windows User in SQL Server Management Studio (2005 or later)

Is there a way in SQL Server Management Studio 2005 (or later) to change the Windows Authentication user (as you could in SQL Server 2000 and older)?在 SQL Server Management Studio 2005(或更高版本)中有没有办法更改 Windows 身份验证用户(就像在 SQL Server 2000 及更早版本中一样)?

This is the general connection properties dialog(note the greyed out UID/PWD when selecting Windows Auth):这是一般的连接属性对话框(注意选择 Windows 身份验证时显示为灰色的 UID/PWD):

对话

FYI - One workaround is to use runas but I'm looking for a solution that will allow me to work with multiple Windows accounts across multiple servers (and across multiple domains).仅供参考 - 一种解决方法是使用runas但我正在寻找一种解决方案,该解决方案将允许我跨多个服务器(以及跨多个域)使用多个 Windows 帐户。

While there's no way to connect to multiple servers as different users in a single instance of SSMS, what you're looking for is the following RUNAS syntax:虽然无法在单个 SSMS 实例中以不同用户的身份连接到多个服务器,但您需要的是以下 RUNAS 语法:

runas /netonly /user:domain\username program.exe

When you use the "/netonly" switch, you can log in using remote credentials on a domain that you're not currently a member of, even if there's no trust set up.当您使用“/netonly”开关时,即使没有设置信任,您也可以在当前不是其成员的域上使用远程凭据登录。 It just tells runas that the credentials will be used for accessing remote resources - the application interacts with the local computer as the currently logged-in user, and interacts with remote computers as the user whose credentials you've given.它只是告诉 runas 凭据将用于访问远程资源 - 应用程序作为当前登录的用户与本地计算机交互,并作为您提供其凭据的用户与远程计算机交互。

You'd still have to run multiple instances of SSMS, but at least you could connect as different windows users in each one.您仍然需要运行多个 SSMS 实例,但至少您可以在每个实例中以不同的 Windows 用户身份进行连接。


For example: runas /netonly /user:domain\\username ssms.exe 例如: runas /netonly /user:domain\\username ssms.exe

Hold shift and right click on SQL Server Mangement studion icon.按住shift并右键单击 SQL Server 管理工作室图标。 You can Run as other windows account user.您可以以其他 Windows 帐户用户身份运行。

One other way that I discovered is to go to "Start" > "Control Panel" > "Stored Usernames and passwords" (Administrative Tools > Credential Manager in Windows 7) and add the domain account that you would use with the "runas" command.我发现的另一种方法是转到“开始”>“控制面板”>“存储的用户名和密码”(Windows 7 中的“管理工具”>“凭据管理器”)并添加您将与“runas”命令一起使用的域帐户.

Then, in SQL Management Studio 2005, just select the "Windows Authentication" and input the server you wanna connect to (even though the user that you can see greyed out is still the local user)... and it works!然后,在 SQL Management Studio 2005 中,只需选择“Windows 身份验证”并输入您要连接的服务器(即使您可以看到灰色的用户仍然是本地用户)......它可以工作!

Don't ask me why !不要问我为什么! :) :)

Edit: Make sure to include ":1433" after the server name in Credential Manager or it may not connect due to not trusting the domain.编辑:确保在凭据管理器中的服务器名称后包含“:1433”,否则可能由于不信任域而无法连接。

None of these answers did what I needed: Login to a remote server using a different domain account than I was logged into on my local machine, and it's a client's domain across a vpn.这些答案都没有满足我的需要:使用与我在本地计算机上登录的域帐户不同的域帐户登录到远程服务器,并且它是跨 vpn 的客户端域。 I don't want to be on their domain!我不想进入他们的领域!

Instead, on the connect to server dialog, select "Windows Authentication", click the Options button, and then on the Additional Connection Parameters tab, enter相反,在“连接到服务器”对话框中,选择“Windows 身份验证”,单击“选项”按钮,然后在“其他连接参数”选项卡上,输入

user id=domain\user;password=password

SSMS won't remember, but it will connect with that account. SSMS 不会记住,但它会连接到该帐户。

The runas /netonly /user:domain\\username program.exe command only worked for me on Windows 10 runas /netonly /user:domain\\username program.exe命令仅适用于Windows 10

  • saving it as a batch file将其保存为批处理文件
  • running it as an administrator,以管理员身份运行,

when running the command batch as regular user I got the wrong password issue mentioned by some users on previous comments.当以普通用户身份运行命令批处理时,我收到了一些用户在先前评论中提到的错误密码问题。

A bit of powershell magic will do the trick:一些 powershell 魔法可以解决这个问题:

cmdkey /add:"SERVER:1433" /user:"DOMAIN\USERNAME" /pass:"PASSWORD"

Then just select windows authentication然后只需选择Windows身份验证

For Windows 10: Go to the Sql Management Studio Icon, or Short Cut in the menu: Right Click > Select Open File Location对于 Windows 10:转到 Sql Management Studio 图标,或菜单中的快捷方式:右键单击 > 选择打开文件位置

在此处输入图片说明

Hold Shift and right Click the shortcut, or ssms.exe file that is in the folder.按住 Shift 并右键单击文件夹中的快捷方式或 ssms.exe 文件。 Holding shift will give you an extra option "Run as different user":按住 shift 会给你一个额外的选项“以不同的用户身份运行”:

在此处输入图片说明

This will pop up a login box and you can type the credentials you would like your session to run under.这将弹出一个登录框,您可以输入您希望会话在其下运行的凭据。

Did anybody tried "plain" runas without parameters?有没有人尝试过没有参数的“普通”runas? Those /netonly /savcecred all of them sound ambiguous and to me utter nonsense.那些 /netonly /savcecred 所有这些听起来模棱两可,对我来说完全是胡说八道。

C:\Windows\System32\runas.exe /user:DOMAINX\OtherUser02 "C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\ssms.exe"

This works just fine.这工作得很好。 No matter what, runas WILL ask you for the user password.无论如何,runas 都会要求您提供用户密码。 Just type it and be security audit compliant.只需键入它并符合安全审计。

No. 没有。

Could you in SQL Server 2000 enterprise manager? 你能在SQL Server 2000企业管理器? I don't recall because Windows auth uses the current logged in user because it relies on the NT login token generated at login time. 我不记得因为Windows auth使用当前登录的用户,因为它依赖于登录时生成的NT登录令牌。

The only way in "Run As". “奔跑”的唯一方法。

Don't you have trust between the domains? 你不相信域名之间的信任吗?

There are many places where someone might want to deploy this kind of scenario, but due to the way integrated authentication works, it is not possible.有很多地方可能有人想要部署这种场景,但由于集成身份验证的工作方式,这是不可能的。

As gbn mentioned, integrated authentication uses a special token that corresponds to your Windows identity.正如 gbn 所提到的,集成身份验证使用与您的 Windows 身份相对应的特殊令牌。 There are coding practices called "impersonation" (probably used by the Run As... command) that allow you to effectively perform an activity as another Windows user, but there is not really a way to arbitrarily act as a different user (à la Linux) in Windows applications aside from that.有一种称为“模拟”的编码实践(可能由 Run As... 命令使用)允许您以另一个 Windows 用户的身份有效地执行活动,但实际上并没有一种方法可以任意充当不同的用户(à la Linux) 在 Windows 应用程序中除此之外。

If you really need to administer multiple servers across several domains, you might consider one of the following:如果您确实需要跨多个域管理多台服务器,您可以考虑以下方法之一:

  1. Set up Domain Trust between your domains so that your account can access computers in the trusting domain在您的域之间设置域信任,以便您的帐户可以访问信任域中的计算机
  2. Configure a SQL user (using mixed authentication) across all the servers you need to administer so that you can log in that way;在您需要管理的所有服务器上配置一个 SQL 用户(使用混合身份验证),以便您可以通过这种方式登录; obviously, this might introduce some security issues and create a maintenance nightmare if you have to change all the passwords at some point.显然,如果您必须在某个时候更改所有密码,这可能会引入一些安全问题并造成维护噩梦。

Hopefully this helps!希望这会有所帮助!

实现您想要的唯一方法是通过右键单击快捷方式并使用“运行方式”功能打开多个 SSMS 实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM