Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SqlConnection.ChangePassword Method (String, SqlCredential, SecureString)

.NET Framework 4.6 and 4.5

Changes the SQL Server password for the user indicated in the SqlCredential object.

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

public static void ChangePassword(
	string connectionString,
	SqlCredential credential,
	SecureString newSecurePassword
)

Parameters

connectionString
Type: System.String

The connection string that contains enough information to connect to a server. The connection string should not use any of the following connection string keywords: Integrated Security = true, UserId, or Password; or ContextConnection = true.

credential
Type: System.Data.SqlClient.SqlCredential

A SqlCredential object.

newSecurePassword
Type: System.Security.SecureString

The new password. newSecurePassword must be read only. The password must also comply with any password security policy set on the server (for example, minimum length and requirements for specific characters).

ExceptionCondition
ArgumentException
  1. The connection string contains any combination of UserId, Password, or Integrated Security=true.

  2. The connection string contains Context Connection=true.

  3. newSecurePassword is greater than 128 characters.

  4. newSecurePassword is not read only.

  5. newSecurePassword is an empty string.

ArgumentNullException

One of the parameters (connectionString, credential, or newSecurePassword) is null.

.NET Framework

Supported in: 4.6, 4.5
Show:
© 2015 Microsoft