SqlConnection.ChangePassword new password does not work immediately
<p>I inherited a web application that has uses individual SQL account for authentication.  I need to update the login procedure to use a different type of hash.</p>

<p>Pseudo code</p>

<pre><code>if (login(newhash(password)) == 0) // login using new hash function doesn't work
{
    if (login(oldhash(password)) == 1) // login with old hash works
    {
        SqlConnection.ChangePassword(connstr);
        login(newhash(password)); 
    }
}
</code></pre>

<p>The problem is the second login(newhash(password) would not immediately work.  If I put a System.Threading.Thread.Sleep(5000) in between the ChangePassword and the login then it would work.  SqlConnection is closed properly when doing the login()</p>

<p>I also tried using sp_password instead, but it still won't authenticate immediately with the new password.  Is there any way to eliminate this "password change lag"?</p>

<p>EDIT:</p>

<p>I added SqlConnection.ClearPool(conn) and the problem persist. SQL Profiler showed the following:</p>

<ol>
<li>Audit Login Failed</li>
<li>Audit Login</li>
<li>SQL:BatchStarting</li>
<li>SQLBatchCompleted</li>
<li>Audit Login Change Password Event</li>
<li>Audit Login</li>
<li>Audit Login Failed</li>
</ol>

<p>So everything is expected from 1-6, however I don't know where does #7 come from.</p>