[英]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.