SqlConnectionStringBuilder.Password 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 SQL Server 帳戶的密碼。
public:
property System::String ^ Password { System::String ^ get(); void set(System::String ^ value); };
public string Password { get; set; }
member this.Password : string with get, set
Public Property Password As String
屬性值
房產價值 Password ,或 String.Empty 是否提供任何價值。
例外狀況
密碼被錯誤設為 null。 請參考下方的程式碼範例。
範例
以下範例展示了如何設定 Password。
using System;
using System.Data.SqlClient;
class Program {
public static void Main() {
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder["Password"] = null;
string aa = builder.Password;
Console.WriteLine(aa.Length);
builder["Password"] = "??????";
aa = builder.Password;
Console.WriteLine(aa.Length);
try {
builder.Password = null;
}
catch (ArgumentNullException e) {
Console.WriteLine("{0}", e);
}
}
}
Imports System.Data.SqlClient
Public Class Program
Public Shared Sub Main()
Dim builder As New SqlConnectionStringBuilder()
builder("Password") = Nothing
Dim aa As String = builder.Password
Console.WriteLine(aa.Length)
builder("Password") = "??????"
aa = builder.Password
Console.WriteLine(aa.Length)
Try
builder.Password = Nothing
Catch e As ArgumentNullException
Console.WriteLine("{0}", e)
End Try
End Sub
End Class
備註
此特性對應於連接字串中的「Password」與「pwd」鍵。
若 Password 未設定,且你取得該值,則回傳值為 Empty。 要重設 連接字串 的密碼,請將 null 傳入 Item 屬性。