我有两个使用集成安全的应用程序。Integrated Security = true一个在连接字符串中赋值,另一个在Integrated Security = SSPI.
集成安全性之间SSPI和上下文中的区别是什么?true
我有两个使用集成安全的应用程序。Integrated Security = true一个在连接字符串中赋值,另一个在Integrated Security = SSPI.
集成安全性之间SSPI和上下文中的区别是什么?true
根据微软的说法,它们是一回事。
时
false,在连接中指定了用户 ID 和密码。如果为 true,则使用当前 Windows 帐户凭据进行身份验证。
可识别的值为true、false、yes、no和sspi(强烈推荐),相当于true。
Integrated Security=true;不适用于所有 SQL 提供程序,与OleDb提供程序一起使用时会引发异常。
所以基本上Integrated Security=SSPI;是首选,因为与SQLClient&OleDB提供者一起工作。
使用 Windows 身份验证
连接数据库服务器推荐使用Windows Authentication,俗称集成安全。要指定 Windows 身份验证,您可以将以下两个键值对中的任何一个与数据提供程序一起使用。NET 框架用于 SQL Server:
Integrated Security = true;
Integrated Security = SSPI;
但是,只有第二个适用于数据提供者.NET Framework OleDb。如果Integrated Security = true为 ConnectionString 设置,则会引发异常。
在数据提供者中指定 Windows 身份验证。NET Framework for ODBC,您应该使用以下键值对。
Trusted_Connection = yes;
资料来源:MSDN:使用连接字符串
如果我们用来查看:)
.Net Reflector的实际代码,许多问题都会得到答案,并且是相同的:SqlConnectiontruesspi
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 方法:
Integrated Security = False:在连接中指定了用户 ID 和密码。Integrated Security = true :当前 Windows 帐户凭据用于身份验证。
Integrated Security = SSPI :这等价于 true。
我们可以避免连接字符串中的用户名和密码属性,并使用集成安全性
让我从Integrated Security = false
false 用户 ID 和密码在连接字符串中指定。
true Windows 帐户凭据用于身份验证。
公认的值为true、false、yes、no和SSPI。
如果指定User IDandPassword并且 Integrated Security 设置为true,则User IDandPassword将被忽略并使用 Integrated Security
True 仅在您使用 .NET SqlClient 库时有效。使用 OLEDB 时无效。SSPI 在您使用 .net SqlClient 库或 OLEDB 时都适用。
在我看来,
如果您不使用 Integrated security=SSPI,那么您需要在连接字符串中对用户名和密码进行硬编码,这意味着“相对不安全”,因为所有员工都可以访问,甚至前员工也可以恶意使用这些信息。