首页 文章

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

提问于
浏览
445

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

在集成安全性的上下文中, SSPItrue 之间有什么区别?

9 回答

  • 379

    根据Microsoft,他们是一回事 .

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

  • 7

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

    所以基本上 Integrated Security=SSPI; 是首选的,因为它适用于 SQLClientOleDB 提供者 .

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

    ![Windows Auth Syntax

  • 60

    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

  • 21

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

    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

  • 30

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

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

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

  • 5

    让我先从 Integrated Security = false 开始

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

    已识别的值为 truefalseyesnoSSPI .

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

  • 119

    请注意,连接字符串特定于 whathow ,您正在连接到数据 . 它们连接到同一个数据库,但第一个是使用.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数据连接 .

  • 13

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

  • 2

    在我看来,

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

相关问题