SqlConnectionStringBuilder.DataSource 속성

정의

연결할 SQL Server 인스턴스의 이름이나 네트워크 주소를 가져오거나 설정합니다.

public:
 property System::String ^ DataSource { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter(typeof(Microsoft.Data.SqlClient.SqlConnectionStringBuilder+SqlDataSourceConverter))]
public string DataSource { get; set; }
public string DataSource { get; set; }
[<System.ComponentModel.TypeConverter(typeof(Microsoft.Data.SqlClient.SqlConnectionStringBuilder+SqlDataSourceConverter))>]
member this.DataSource : string with get, set
member this.DataSource : string with get, set
Public Property DataSource As String

속성 값

DataSource 속성의 값이거나, 제공된 값이 없으면 String.Empty입니다.

특성

예외

값을 null로 설정하려면 Value를 사용합니다.

예제

다음 예제에서는 SqlConnectionStringBuilder 클래스가 "Data Source" 연결 문자열 키의 동의어를 잘 알려진 키로 변환하는 것을 보여 줍니다.

using Microsoft.Data.SqlClient;

class Program
{
    static void Main()
    {
        SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(
            "Network Address=(local);Integrated Security=SSPI;" +
            "Initial Catalog=AdventureWorks");

        // Display the connection string, which should now 
        // contain the "Data Source" key, as opposed to the 
        // supplied "Network Address".
        Console.WriteLine(builder.ConnectionString);

        // Retrieve the DataSource property.
        Console.WriteLine("DataSource = " + builder.DataSource);

        Console.WriteLine("Press any key to continue.");
        Console.ReadLine();
    }
}

설명

이 속성은 연결 문자열 내의 "Data Source", "server", "address", "addr" 및 "network address" 키에 해당합니다. 제공된 된 연결 문자열 내에서 어떤이 값을 제공 하는 것에 관계 없이 연결 문자열에서 만든는 SqlConnectionStringBuilder 잘 알려진 "Data Source" 키를 사용 합니다.

포트 번호는 서버 이름 server=tcp:servername, portnumber다음에 지정할 수 있습니다.

로컬 instance 지정할 때는 항상 (로컬)을 사용합니다. 프로토콜을 강제로 적용하려면 다음 접두사 중 하나를 추가합니다np:(local), tcp:(local), lpc:(local).

다음과 같이 LocalDB 데이터베이스에 연결할 수도 있습니다. server=(localdb)\\myInstance LocalDB에 대한 자세한 내용은 LocalDB에 대한 SqlClient 지원을 참조하세요. 데이터 원본 은 TCP 형식 또는 명명된 파이프 형식을 사용해야 합니다. TCP 형식은 다음과 같습니다.

  • tcp:<host name>\<instance name>
  • tcp:<host name,TCP></IP 포트 번호>

TCP 형식은 "tcp:" 접두사로 시작해야 하며 호스트 이름 및 instance 이름으로 지정된 대로 데이터베이스 instance 뒤에 와야 합니다. 이 형식은 Azure SQL 데이터베이스에 연결할 때는 적용되지 않습니다. 프로토콜이 지정되지 않은 경우 Azure SQL Database에 연결하기 위해 TCP가 자동으로 선택됩니다.

호스트 이름은 다음 방법 중 하나로 지정해야 합니다.

  • NetBIOSName
  • IPv4Address
  • IPv6Address

instance 이름은 데이터베이스 instance 호스트되는 특정 TCP/IP 포트 번호를 resolve 데 사용됩니다. 또는 TCP/IP 포트 번호를 직접 지정할 수도 있습니다. instance 이름과 포트 번호가 모두 없는 경우 기본 데이터베이스 instance 사용됩니다.

명명된 파이프 형식은 다음과 같습니다.

  • np:\\<host name>\pipe\<pipe name>

명명된 파이프 형식은 접두사 "np:"로 시작해야 하며 명명된 파이프 이름이 뒤에 와야 합니다.

호스트 이름은 다음 방법 중 하나로 지정해야 합니다.

  • NetBIOSName
  • IPv4Address
  • IPv6Address

파이프 이름은 .NET 애플리케이션이 연결할 데이터베이스 instance 식별하는 데 사용됩니다.

네트워크 키의 값을 지정하면 접두사 "tcp:" 및 "np:"를 지정하면 안 됩니다. 참고: tcp 접두사를 연결 문자열의 서버 이름에 접두사로 지정하거나 localhost를 사용하여 공유 메모리 대신 TCP를 강제로 사용할 수 있습니다.

적용 대상