C# 当使用 Trusted_Connection=true 和 SQL Server 身份验证时,这会影响性能吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1642483/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 19:37:26  来源:igfitidea点击:

When using Trusted_Connection=true and SQL Server authentication, will this affect performance?

c#.netasp.netsql-server-2005ado.net

提问by George2

If a connection string specifies Trusted_Connection=truewith SQL Server authentication mode, will performance of my web application be impacted?

如果连接字符串指定Trusted_Connection=true为 SQL Server 身份验证模式,我的 Web 应用程序的性能是否会受到影响?

采纳答案by marc_s

Not 100% sure what you mean:

不是 100% 确定你的意思:

Trusted_Connection=True;

ISusing Windows credentials and is 100% equivalent to:

正在使用 Windows 凭据并且 100% 等效于:

Integrated Security=SSPI;

or

或者

Integrated Security=true;

If you don't want to use integrated security / trusted connection, you need to specify user id and password explicitly in the connection string (and leave out any reference to Trusted_Connectionor Integrated Security)

如果您不想使用集成安全/可信连接,则需要在连接字符串中明确指定用户 ID 和密码(并省略对Trusted_Connection或 的任何引用Integrated Security

server=yourservername;database=yourdatabase;user id=YourUser;pwd=TopSecret

Only in this case, the SQL Server authentication mode is used.

只有在这种情况下,才会使用 SQL Server 身份验证模式。

If any of these two settings is present (Trusted_Connection=trueor Integrated Security=true/SSPI), then the Windows credentialsof the current user are used to authenticate against SQL Server and any user iD=setting will be ignored and notused.

如果存在这两个设置中的任何一个(Trusted_Connection=trueIntegrated Security=true/SSPI),则当前用户的Windows 凭据用于对 SQL Server 进行身份验证,并且任何user iD=设置都将被忽略和使用。

For reference, see the Connection Strings sitefor SQL Server 2005 with lots of samples and explanations.

有关参考,请参阅SQL Server 2005的连接字符串站点,其中包含大量示例和说明。

Using Windows Authentication is the preferred and recommended way of doing things, but it might incur a slight delay since SQL Server would have to authenticate your credentials against Active Directory (typically). I have no idea how much that slight delay might be, and I haven't found any references for that.

使用 Windows 身份验证是首选和推荐的处理方式,但它可能会产生轻微的延迟,因为 SQL Server 必须针对 Active Directory(通常)验证您的凭据。我不知道这种轻微的延迟可能有多少,而且我还没有找到任何参考资料。



Summing up:

加起来:

If you specify either Trusted_Connection=True;or Integrated Security=SSPI;or Integrated Security=true;in your connection string

如果指定Trusted_Connection=True;Integrated Security=SSPI;Integrated Security=true;在您的连接字符串

==> THEN(and only then) you have Windows Authenticationhappening. Any user id=setting in the connection string will be ignored.

==>那么(并且只有那时)您才会进行Windows 身份验证user id=连接字符串中的任何设置都将被忽略



If you DO NOTspecify either of those settings,

如果您没有指定这些设置中的任何一个,

==> then you DO NOThave Windows Authentication happening (SQL Authentication mode will be used)

==> 那么你没有进行 Windows 身份验证(将使用 SQL 身份验证模式)



回答by Darin Dimitrov

This will probably have some performance costs when creating the connection but as connections are pooled, they are created only once and then reused, so it won't make any difference to your application. But as always: measure it.

这在创建连接时可能会产生一些性能成本,但由于连接是池化的,它们只创建一次然后重用,因此它不会对您的应用程序产生任何影响。但一如既往:衡量它。



UPDATE:

更新:

There are two authentication modes:

有两种认证模式:

  1. Windows Authentication mode (corresponding to a trusted connection). Clients need to be members of a domain.
  2. SQL Server Authentication mode. Clients are sending username/password at each connection
  1. Windows 身份验证模式(对应于受信任的连接)。客户端需要是域的成员。
  2. SQL Server 身份验证模式。客户端在每次连接时发送用户名/密码

回答by Tror

When you use trusted connections, username and password are IGNORED, because SQL Server using windows authentication.

当您使用受信任的连接时,用户名和密码将被忽略,因为 SQL Server 使用 Windows 身份验证。

回答by Joe

If your web application is configured to impersonate a client, then using a trusted connection will potentially have a negative performance impact. This is because each client must use a different connection pool (with the client's credentials).

如果您的 Web 应用程序配置为模拟客户端,则使用受信任的连接可能会对性能产生负面影响。这是因为每个客户端必须使用不同的连接池(使用客户端的凭据)。

Most web applications don't use impersonation / delegation, and hence don't have this problem.

大多数 Web 应用程序不使用模拟/委托,因此不存在此问题。

See this MSDN articlefor more information.

有关更多信息,请参阅此 MSDN 文章