SqlConnectionStringBuilder.Password Vlastnost

Definice

Získá nebo nastaví heslo pro účet SQL Server.Gets or sets the password for the SQL Server account.

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

Hodnota vlastnosti

String

Hodnota Password vlastnosti, nebo String.Empty Pokud žádná nebyla zadána.The value of the Password property, or String.Empty if none has been supplied.

Výjimky

Heslo bylo nesprávně nastaveno na hodnotu null.The password was incorrectly set to null. Viz Ukázka kódu níže.See code sample below.

Příklady

Následující příklad ukazuje, jak nastavit Password .The following example shows how to set 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

Poznámky

Tato vlastnost odpovídá klíčům "heslo" a "PWD" v připojovacím řetězci.This property corresponds to the "Password" and "pwd" keys within the connection string.

Pokud nebyla Password nastavena a načítáte hodnotu, vrácená hodnota je Empty .If Password has not been set and you retrieve the value, the return value is Empty. Chcete-li obnovit heslo připojovacího řetězce, předejte hodnotu null vlastnosti Item.To reset the password for the connection string, pass null to the Item property.

Platí pro