简体   繁体   English

如何使用其他Windows帐户连接到SQL Server

[英]How to connect to SQL Server with a different windows account

I have a C# windows application from which I need to connect to a SQL Server database and access the tables, with a different windows account.(Other than the logged in account) 我有一个C#windows应用程序,我需要连接到SQL Server数据库并访问表,使用不同的Windows帐户。(登录帐户除外)

What is the best approach for this. 对此最好的方法是什么?

Most commonly for SQL Server, I would use integrated security, so a connection string like this: 最常用于SQL Server,我会使用集成安全性,所以像这样的连接字符串:

var connectionString = string.Format("Data Source={0};Initial Catalog={1};Integrated Security=SSPI;", hostName, databaseName);

If you need to connect as a different user, which you're not logged in as, then you need to specify the username / password combination in the connection string, like this: 如果您需要以不登录的其他用户身份进行连接,则需要在连接字符串中指定用户名/密码组合,如下所示:

var connectionString = string.Format("Data Source={0};Initial Catalog={1};User ID={2};Password={3};", hostName, databaseName, anotherUsername, anotherPassword);

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

相关问题 连接字符串,用于使用其他Windows帐户连接SQL Server - Connection String to connect a SQL Server using another windows account 有没有一种方法可以使用网络服务帐户将Windows C#应用程序连接到SQL Server - Is there a way to connect Windows C# Application to SQL Server using a Network Service Account 如何使用Windows Phone 8连接到服务器上已托管的SQL Server数据库 - How to connect to a SQL Server database already hosted on server with windows phone 8 使用Windows身份验证连接到SQL Server - Connect to SQL Server with windows authentication 禁用Sql Server Windows登录帐户? - Disable Sql Server Windows Login Account? 将Windows Phone和Windows 8应用程序连接到SQL Server - Connect Windows Phone and Windows 8 apps to SQL Server 如何使用客户端Windows凭据连接到Web中的SQL Server数据库 - How to connect to SQL Server database in web using client windows credentials 如何从 Windows 10 UWP 应用程序连接到 SQL 服务器数据库 - How to connect to SQL server database from a Windows 10 UWP app 如何使用Windows身份验证远程连接到SQL Server数据库? - How to connect to SQL Server database using windows authentication remotely? 如何连接到ASP.Net中不同域中的SQL Server? - How to connect to a SQL Server in a different domain in ASP.Net?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM