Export (0) Print
Expand All

SqlConnectionStringBuilder.Password Property

Gets or sets the password for the SQL Server account.

Namespace:  System.Data.SqlClient
Assembly:  System.Data (in System.Data.dll)

'Declaration
Public Property Password As String

Property Value

Type: System.String
The value of the Password property, or String.Empty if none has been supplied.

ExceptionCondition
ArgumentNullException

The password was incorrectly set to null. See code sample below.

This property corresponds to the "Password" and "pwd" keys within the connection string.

If Password has not been set and you retrieve the value, the return value is Empty. To reset the password for the connection string, pass null to the Item property.

The following example shows how to set Password.

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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft