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

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

在集成安全的背景下, SSPItrue之间有什么区别?


#1楼

让我先从Integrated Security = false

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

认可的值是truefalseyesnoSSPI

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


#2楼

使用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:使用连接字符串


#3楼

据微软称,他们是一回事。

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


#4楼

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

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

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


#5楼

如果我们使用.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


#6楼

需要注意的是连接字符串是特定于您要连接到的数据什么如何 。 它们连接到同一个数据库,但第一个是使用.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数据连接。

  • 什么是sspi ?
  • 连接字符串语法

#7楼

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

所以基本上Integrated Security=SSPI; 因为适用于SQLClientOleDB提供程序,所以是首选。

这是根据MSDN的完整语法集- 连接字符串语法(ADO.NET)


#8楼

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


#9楼

在我看来,

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

你可能感兴趣的:(Integrated Security = True和Integrated Security = SSPI有什么区别?)