SqlConnectionStringBuilder.DataSource 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定要連線之 SQL Server 實例的名稱或網路位址。
public:
property System::String ^ DataSource { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter(typeof(System.Data.SqlClient.SqlConnectionStringBuilder+SqlDataSourceConverter))]
public string DataSource { 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 是否提供任何價值。
- 屬性
例外狀況
要將值設為空,請使用 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
備註
此特性對應於 連接字串 中的「Data Source」、「server」、「address」、「addr」及「network address」鍵。 無論在所提供的連接字串中提供了哪一個值,由 建立 SqlConnectionStringBuilder 的連接字串都會使用眾所周知的「資料來源」鍵。