我有两个使用集成安全性的应用程序 . 一个在连接字符串中指定 Integrated Security = true ,另一个设置 Integrated Security = SSPI .
Integrated Security = true
Integrated Security = SSPI
在集成安全性的上下文中, SSPI 和 true 之间有什么区别?
SSPI
true
根据Microsoft,他们是一回事 .
如果为false,则在连接中指定用户ID和密码 . 如果为true,则使用当前Windows帐户凭据进行身份验证 . 识别的值是true,false,yes,no和sspi(强烈推荐),这相当于true .
Integrated Security=true; 在所有SQL提供程序中都不起作用,它在与 OleDb 提供程序一起使用时会引发异常 .
Integrated Security=true;
OleDb
所以基本上 Integrated Security=SSPI; 是首选的,因为它适用于 SQLClient 和 OleDB 提供者 .
Integrated Security=SSPI;
SQLClient
OleDB
这是根据MSDN - Connection String Syntax (ADO.NET)的完整语法集
![
Using Windows Authentication
建议使用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
如果我们使用 .Net Reflector 来查看 SqlConnection :) true 和 sspi 的实际代码是相同的,那么很多问题都会得到答案:
.Net Reflector
SqlConnection
sspi
internal class DbConnectionOptions ... internal bool ConvertValueToIntegratedSecurityInternal(string stringValue) { if ((CompareInsensitiveInvariant(stringValue, "sspi") || CompareInsensitiveInvariant(stringValue, "true")) || CompareInsensitiveInvariant(stringValue, "yes")) { return true; } } ...
EDIT 20.02.2018 现在在.Net Core中我们可以在github上看到它的开源!搜索ConvertValueToIntegratedSecurityInternal方法:
https://github.com/dotnet/corefx/blob/fdbb160aeb0fad168b3603dbdd971d568151a0c8/src/System.Data.SqlClient/src/System/Data/Common/DbConnectionOptions.cs
Integrated Security = False:在连接中指定用户ID和密码 . Integrated Security = true:当前的Windows帐户凭据用于身份验证 .
集成安全性= SSPI:这与真实相当 .
我们可以避免连接字符串中的用户名和密码属性,并使用集成安全性
让我先从 Integrated Security = false 开始
Integrated Security = false
false 用户ID和密码在连接字符串中指定 .true Windows帐户凭据用于身份验证 .
已识别的值为 true , false , yes , no 和 SSPI .
false
yes
no
如果指定 User ID 和 Password 并且Integrated Security设置为 true ,则将忽略 User ID 和 Password 并将使用Integrated Security
User ID
Password
请注意,连接字符串特定于 what 和 how ,您正在连接到数据 . 它们连接到同一个数据库,但第一个是使用.NET Framework Data Provider for SQL Server . Integrated Security = True对OleDb不起作用 .
数据源= . ;初始目录= aspnetdb;集成安全性=真
Provider = SQLOLEDB; Data Source = .; Integrated Security = SSPI; Initial Catalog = aspnetdb
如有疑问,请使用Visual Studio Server Explorer数据连接 .
什么是sspi?
Connection Strings Syntax
True仅在您使用.NET SqlClient库时才有效 . 使用OLEDB时无效 . 无论您使用.net SqlClient库还是OLEDB,SSPI都是bvaid .
在我看来,
如果你不使用集成安全性= SSPI,那么你需要在连接字符串中硬编码用户名和密码,这意味着“相对不安全”为什么,因为所有员工都有访问权限甚至前雇员都可以恶意使用这些信息 .
9 回答
根据Microsoft,他们是一回事 .
Integrated Security=true;
在所有SQL提供程序中都不起作用,它在与OleDb
提供程序一起使用时会引发异常 .所以基本上
Integrated Security=SSPI;
是首选的,因为它适用于SQLClient
和OleDB
提供者 .这是根据MSDN - Connection String Syntax (ADO.NET)的完整语法集
![
Using Windows Authentication
建议使用Windows身份验证(通常称为集成安全性)连接到数据库服务器 . 要指定Windows身份验证,可以将以下两个键值对中的任何一个与数据提供程序一起使用 . 用于SQL Server的.NET Framework:
但是,只有第二个适用于数据提供程序.NET Framework OleDb . 如果为ConnectionString设置
Integrated Security = true
,则抛出异常 .在数据提供程序中指定Windows身份验证 . 在.NET Framework for ODBC中,您应该使用以下键值对 .
资料来源:MSDN: Working with Connection Strings
如果我们使用
.Net Reflector
来查看SqlConnection
:)true
和sspi
的实际代码是相同的,那么很多问题都会得到答案:EDIT 20.02.2018 现在在.Net Core中我们可以在github上看到它的开源!搜索ConvertValueToIntegratedSecurityInternal方法:
https://github.com/dotnet/corefx/blob/fdbb160aeb0fad168b3603dbdd971d568151a0c8/src/System.Data.SqlClient/src/System/Data/Common/DbConnectionOptions.cs
Integrated Security = False:在连接中指定用户ID和密码 . Integrated Security = true:当前的Windows帐户凭据用于身份验证 .
集成安全性= SSPI:这与真实相当 .
我们可以避免连接字符串中的用户名和密码属性,并使用集成安全性
让我先从
Integrated Security = false
开始false 用户ID和密码在连接字符串中指定 .
true Windows帐户凭据用于身份验证 .
已识别的值为
true
,false
,yes
,no
和SSPI
.如果指定
User ID
和Password
并且Integrated Security设置为true
,则将忽略User ID
和Password
并将使用Integrated Security请注意,连接字符串特定于 what 和 how ,您正在连接到数据 . 它们连接到同一个数据库,但第一个是使用.NET Framework Data Provider for SQL Server . Integrated Security = True对OleDb不起作用 .
数据源= . ;初始目录= aspnetdb;集成安全性=真
Provider = SQLOLEDB; Data Source = .; Integrated Security = SSPI; Initial Catalog = aspnetdb
如有疑问,请使用Visual Studio Server Explorer数据连接 .
什么是sspi?
Connection Strings Syntax
True仅在您使用.NET SqlClient库时才有效 . 使用OLEDB时无效 . 无论您使用.net SqlClient库还是OLEDB,SSPI都是bvaid .
在我看来,
如果你不使用集成安全性= SSPI,那么你需要在连接字符串中硬编码用户名和密码,这意味着“相对不安全”为什么,因为所有员工都有访问权限甚至前雇员都可以恶意使用这些信息 .