Export (0) Print
Expand All

SqlConnection.ChangePassword Method (String, SqlCredential, SecureString)

.NET Framework 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


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.

Type: System.Data.SqlClient.SqlCredential

A SqlCredential object.

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).

  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.


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

.NET Framework

Supported in: 4.6, 4.5

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.

© 2014 Microsoft