SqlConnectionStringBuilder.Password 屬性

定義

取得或設定 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 屬性。

適用於

另請參閱