SqlConnectionStringBuilder.DataSource Свойство

Определение

Возвращает или задает имя или сетевой адрес экземпляра SQL Server для подключения.

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

Значение свойства

Значение DataSource свойства или String.Empty значение, если оно не было предоставлено.

Атрибуты

Исключения

Чтобы задать значение NULL, используйте Value.

Примеры

В следующем примере показано, что класс SqlConnectionStringBuilder преобразует синонимы для ключа источника данных строка подключения в известный ключ:

using System.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();
    }
}
Imports System.Data.SqlClient

Module Module1

    Sub Main()
        Dim builder As _
         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()
    End Sub
End Module

Комментарии

Это свойство соответствует ключам "Источник данных", "сервер", "адрес", "addr" и "сетевой адрес" в строка подключения. Независимо от того, какие из этих значений были предоставлены в указанной строке подключения, строка подключения, созданная с помощью SqlConnectionStringBuilder известного ключа "Источник данных".

Применяется к

См. также раздел