SqlConnectionStringBuilder.IntegratedSecurity 속성

정의

연결에 사용자 ID와 암호가 지정되었는지(false인 경우) 아니면 현재 Windows 계정 자격 증명이 인증에 사용되는지(true인 경우)를 나타내는 부울 값을 가져오거나 설정합니다.

public:
 property bool IntegratedSecurity { bool get(); void set(bool value); };
public bool IntegratedSecurity { get; set; }
member this.IntegratedSecurity : bool with get, set
Public Property IntegratedSecurity As Boolean

속성 값

IntegratedSecurity 속성의 값이거나, 제공된 값이 없으면 false입니다.

예제

다음 예제에서는 기존 연결 문자열을 SQL Server 인증 사용에서 통합 보안 사용으로 변환합니다. 이 예제에서는 연결 문자열에서 사용자 이름과 암호를 제거한 다음 IntegratedSecurity 개체의 SqlConnectionStringBuilder 속성을 설정하여 이 작업을 수행합니다.

참고

이 예제에는 SqlConnectionStringBuilder가 연결 문자열로 작업하는 방법을 보여 주기 위한 암호가 포함되어 있습니다. 애플리케이션에서는 Windows 인증을 사용하는 것이 좋습니다. 암호를 사용해야 하는 경우에는 애플리케이션에 하드 코드된 암호를 포함하지 마십시오.

using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        try
        {
            string connectString =
                "Data Source=(local);User ID=ab;Password=MyPassword;" +
                "Initial Catalog=AdventureWorks";

            SqlConnectionStringBuilder builder =
                new SqlConnectionStringBuilder(connectString);
            Console.WriteLine("Original: " + builder.ConnectionString);

            // Use the Remove method
            // in order to reset the user ID and password back to their
            // default (empty string) values. Simply setting the
            // associated property values to an empty string won't
            // remove them from the connection string; you must
            // call the Remove method.
            builder.Remove("User ID");
            builder.Remove("Password");

            // Turn on integrated security:
            builder.IntegratedSecurity = true;

            Console.WriteLine("Modified: " + builder.ConnectionString);

            using (SqlConnection connection =
                       new SqlConnection(builder.ConnectionString))
            {
                connection.Open();
                // Now use the open connection.
                Console.WriteLine("Database = " + connection.Database);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        Console.WriteLine("Press any key to finish.");
        Console.ReadLine();
    }
}
Imports System.Data.SqlClient
    
Module Module1
    Sub Main()
        Try
            Dim connectString As String = _
             "Data Source=(local);User ID=ab;Password=MyPassword;" & _
             "Initial Catalog=AdventureWorks"

            Dim builder As New SqlConnectionStringBuilder(connectString)
            Console.WriteLine("Original: " & builder.ConnectionString)

            ' Use the Remove method
            ' in order to reset the user ID and password back to their
            ' default (empty string) values. Simply setting the 
            ' associated property values to an empty string won't
            ' remove them from the connection string; you must
            ' call the Remove method.
            builder.Remove("User ID")
            builder.Remove("Password")

            ' Turn on integrated security.
            builder.IntegratedSecurity = True

            Console.WriteLine("Modified: " & builder.ConnectionString)

            Using connection As New SqlConnection(builder.ConnectionString)
                connection.Open()
                ' Now use the open connection.
                Console.WriteLine("Database = " & connection.Database)
            End Using

        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try

        Console.WriteLine("Press any key to finish.")
        Console.ReadLine()
    End Sub
End Module

설명

이 속성은 연결 문자열 내의 "Integrated Security" 및 "trusted_connection" 키에 해당합니다.

적용 대상

추가 정보