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 属性。

适用于

另请参阅