簡體   English   中英

如何使用其他Windows帳戶連接到SQL Server

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

我有一個C#windows應用程序,我需要連接到SQL Server數據庫並訪問表,使用不同的Windows帳戶。(登錄帳戶除外)

對此最好的方法是什么?

最常用於SQL Server,我會使用集成安全性,所以像這樣的連接字符串:

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

如果您需要以不登錄的其他用戶身份進行連接,則需要在連接字符串中指定用戶名/密碼組合,如下所示:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM