sa密码都记录在mmsqlmanager上,以及heidisql上了,时间久了就忘记了,而当遇到操作数据库反复提示权限不够的问题的时候。检查sa权限指派是路径之一,可是,sa密码都忘记了,不敢造次直接编辑客户端已经记住的密码。可以只用bat去探索自己依稀记得可能的密码串:
$server = "localhost" $user = "sa" $passwords = @("password1", "password2", "password3") foreach ($password in $passwords) { Write-Host "Testing password: $password" try { $connectionString = "Server=$server;Database=master;User Id=$user;Password=$password;" $connection = New-Object System.Data.SqlClient.SqlConnection($connectionString) $connection.Open() Write-Host "Password is: $password" $connection.Close() exit } catch { Write-Host "Failed to connect with password: $password" } } Write-Host "No valid password found."
这个保存为.bat运行,密码方面就自己组合替换。
poweshell的语法只细微变化了一点:
$server = "localhost" $user = "sa" $passwords = @("password1", "password2", "password3") foreach ($password in $passwords) { Write-Host "Testing password: $password" try { $connectionString = "Server=$server;Database=master;User Id=$user;Password=$password;" $connection = New-Object System.Data.SqlClient.SqlConnection($connectionString) $connection.Open() Write-Host "Password is: $password" $connection.Close() exit } catch { Write-Host "Failed to connect with password: $password" } } Write-Host "No valid password found."