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 未提供任何值。
- 属性
例外
若要将值设置为 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 该字符串创建的连接字符串都将使用已知的“数据源”密钥。