Integrated Security = True和Integrated Security = SSPI有什么区别?

问题描述 投票:472回答:9

我有两个使用集成安全性的应用程序。一个在连接字符串中指定Integrated Security = true,另一个设置Integrated Security = SSPI

在综合安全的背景下,SSPItrue有什么区别?

sql-server security connection-string database-security
9个回答
400
投票

Microsoft说,他们是一回事。

在连接中指定false,用户ID和密码时。如果为true,则使用当前Windows帐户凭据进行身份验证。 认可的值是truefalseyesnosspi(强烈推荐),相当于true


136
投票

Integrated Security=true;在所有SQL提供程序中都不起作用,它在与OleDb提供程序一起使用时会抛出异常。

所以基本上Integrated Security=SSPI;是首选,因为与SQLClientOleDB提供商合作。

根据MSDN - Connection String Syntax (ADO.NET),这是完整的语法集

![Windows Auth Syntax


64
投票

使用Windows身份验证

建议使用Windows身份验证(通常称为集成安全性)连接到数据库服务器。要指定Windows身份验证,可以将以下两个键值对中的任何一个与数据提供程序一起使用。用于SQL Server的.NET Framework:

 Integrated Security = true;
 Integrated Security = SSPI;

但是,只有第二个适用于数据提供程序.NET Framework OleDb。如果为ConnectionString设置Integrated Security = true,则抛出异常。

在数据提供程序中指定Windows身份验证。在.NET Framework for ODBC中,您应该使用以下键值对。

Trusted_Connection = yes;

资料来源:MSDN: Working with Connection Strings


31
投票

如果我们使用.Net Reflector查看SqlConnection的实际代码,很多问题都会得到答案:) truesspi是相同的:

internal class DbConnectionOptions

...

internal bool ConvertValueToIntegratedSecurityInternal(string stringValue)
{
    if ((CompareInsensitiveInvariant(stringValue, "sspi") || CompareInsensitiveInvariant(stringValue, "true")) || CompareInsensitiveInvariant(stringValue, "yes"))
    {
        return true;
    }
}

...

编辑20.02.2018现在在.Net Core我们可以在github上看到它的开源!搜索ConvertValueToIntegratedSecurityInternal方法:

https://github.com/dotnet/corefx/blob/fdbb160aeb0fad168b3603dbdd971d568151a0c8/src/System.Data.SqlClient/src/System/Data/Common/DbConnectionOptions.cs


21
投票

Integrated Security = False:在连接中指定用户ID和密码。 Integrated Security = true:当前Windows帐户凭据用于身份验证。

集成安全性= SSPI:这与真实相当。

我们可以避免连接字符串中的用户名和密码属性,并使用集成安全性


13
投票

让我先从Integrated Security = false开始

false用户ID和密码在连接字符串中指定。 true Windows帐户凭据用于身份验证。

公认的值是truefalseyesnoSSPI

如果指定了User IDPassword并且将Integrated Security设置为true,则将忽略User IDPassword并使用Integrated Security


7
投票

请注意,连接字符串特定于您连接数据的方式和方式。它们连接到同一个数据库,但第一个是使用.NET Framework Data Provider for SQL Server。 Integrated Security = True对OleDb不起作用。

  • Data Source = .; Initial Catalog = aspnetdb; Integrated Security = True
  • Provider = SQLOLEDB; Data Source = .; Integrated Security = SSPI; Initial Catalog = aspnetdb

如有疑问,请使用Visual Studio Server Explorer数据连接。


5
投票

True仅在您使用.NET SqlClient库时才有效。使用OLEDB时无效。无论您使用.net SqlClient库还是OLEDB,SSPI都是bvaid。


2
投票

在我看来,

如果你不使用集成安全性= SSPI,那么你需要在连接字符串中硬编码用户名和密码,这意味着“相对不安全”为什么,因为所有员工都有访问权限甚至前雇员都可以恶意使用这些信息。

© www.soinside.com 2019 - 2024. All rights reserved.