在 SQL Server Management Studio(2005 或更高版本)中连接不同的 Windows 用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/849149/
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
Connect different Windows User in SQL Server Management Studio (2005 or later)
提问by Matt P.
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 帐户。
回答by SqlRyan
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. 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.
当您使用“/netonly”开关时,您可以使用远程凭据登录您当前不是其成员的域,即使没有设置信任。它只是告诉 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 用户身份进行连接。
例如:
runas /netonly /user:domain\username ssms.exe
runas /netonly /user:domain\username ssms.exe
回答by Suresh
Hold shiftand right click on SQL Server Mangement studion icon. You can Run as other windows account user.
按住shift并右键单击 SQL Server 管理工作室图标。您可以以其他 Windows 帐户用户身份运行。
回答by Suresh
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”,否则可能由于不信任域而无法连接。
回答by Dave
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. I don't want to be on their domain!
这些答案都没有满足我的需要:使用与我在本地计算机上登录的域帐户不同的域帐户登录到远程服务器,并且它是跨 vpn 的客户端域。我不想进入他们的领域!
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 不会记住,但它会连接到该帐户。
回答by Ricardo Mercado
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.
当以普通用户身份运行命令批处理时,我收到了一些用户在先前评论中提到的错误密码问题。
回答by maeneak
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身份验证
回答by cmartin
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. Holding shift will give you an extra option "Run as different user":
按住 Shift 并右键单击文件夹中的快捷方式或 ssms.exe 文件。按住 shift 会给你一个额外的选项“以不同的用户身份运行”:
This will pop up a login box and you can type the credentials you would like your session to run under.
这将弹出一个登录框,您可以输入您希望会话在其下运行的凭据。
回答by Ed Altorfer
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. 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.
正如 gbn 所提到的,集成身份验证使用与您的 Windows 身份相对应的特殊令牌。有一些称为“模拟”的编码实践(可能由 Run As... 命令使用)允许您以另一个 Windows 用户的身份有效地执行活动,但实际上并没有一种方法可以任意充当不同的用户(à la Linux) 在 Windows 应用程序中除此之外。
If you really need to administer multiple servers across several domains, you might consider one of the following:
如果您确实需要跨多个域管理多台服务器,您可以考虑以下方法之一:
- Set up Domain Trustbetween your domains so that your account can access computers in the trusting domain
- Configure a SQL user (using mixed authentication) across all the servers you need to administer so that you can log in that way; obviously, this might introduce some security issues and create a maintenance nightmare if you have to change all the passwords at some point.
- 在您的域之间设置域信任,以便您的帐户可以访问信任域中的计算机
- 在您需要管理的所有服务器上配置一个 SQL 用户(使用混合身份验证),以便您可以通过这种方式登录;显然,如果您必须在某个时候更改所有密码,这可能会引入一些安全问题并造成维护噩梦。
Hopefully this helps!
希望这会有所帮助!
回答by SQLChicken
The only way to achieve what you want is opening several instances of SSMS by right clicking on shortcut and using the 'Run-as' feature.
实现您想要的唯一方法是通过右键单击快捷方式并使用“运行方式”功能打开多个 SSMS 实例。