SqlConnectionStringBuilder.DataSource 属性     
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置要连接到的 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, setPublic Property DataSource As String属性值
为 DataSource 属性的值,或者,如果未提供任何值,则为 String.Empty。
- 属性
例外
若要将值设置为 null,请使用 Value。
示例
以下示例演示 SqlConnectionStringBuilder 类将“Data Source”连接字符串键的同义词转换为已知键:
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
注解
此属性与连接字符串内的“Data Source”、“server”、“address”、“addr”和“network address”键相对应。 无论在提供的连接字符串中提供了这些值中的哪一个,由 SqlConnectionStringBuilder 创建的连接字符串都将使用已知的“数据源”键。