我登录使用SQL Server数据库的登录帐户我的应用程序。但是,当用户的密码已过期,我只能用错误:18488捕获错误消息。并显示一条消息给用户
I'm logging on my application using Sql Server Database logon account. However, when a user's password is expired, i can only catch the error message using "error:18488" and display a message to user.
当我登入使用SQL Server Management Studio和使用过期密码的帐户,将出现一个对话框,要求我更改密码。
When I login using Sql Server Management Studio with an account with expired password, a dialog box requiring me to change password appears.
有没有办法让我的应用程序与类似T-SQL语句更改过期的密码?
Is there a way to allow my application to change the expired password with something like T-Sql statement?
我已经找到了解决方案 ,我用 SqlConnection.ChangePassword()
。
I've found the solution here, I used SqlConnection.ChangePassword()
.
这里的code:
class Program
{
static void Main(string[] args)
{
System.Data.SqlClient.SqlConnection.ChangePassword(
"Data Source=a_server;Initial Catalog=a_database;UID=user;PWD=old_password",
"new_password");
}
}
希望它可以帮助他人。 :)
Hope it helps others too. :)