最近把SQLServer数据库升级到了2019,某一天突然所有站点都无法访问了,查看了日志发现是数据库连接失败了。
Path: /Contents/1276, Endpoint: DotNetCoreWeb.Areas.Web.Controllers.ContentsController.IndexAsync (DotNetCoreWeb), Error: System.Data.SqlClient.SqlException (0x80131904): 用户 'xxx' 登录失败。原因: 该帐户的密码已过期。
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey,
太失误了,忘记关闭数据库密码强制过期了。SQL Server会要求用户定期更改密码,以提高数据库的安全性。强制密码过期的时间也是可以由管理员设置的。但是不建议设置过期时间,否则突然过期会导致网站应用连接数据库失败。
赶紧使用Microsoft SQL Server Management Studio连接数据库设置密码。使用SQL Server身份验证方式用过期的用户登录,使用过期的密码登录成功后会提示修改密码。设置的新密码可以和旧密码相同,这样就不需要改连接字符串了。
防止SQL Server数据库密码强制过期的方法是:
1. 连接数据库,点击数据库>安全性>登录名,选择要设置的用户名。
2. 右键用户>属性,打开用户登录属性窗口,将强制密码过期选项的勾去掉,点击确认保存。
这样数据库用户的密码就不会过期了。