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