• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

spurious ALTER LOGIN error sql server 2008 R2

I have a web form that is invoked by the current sql user to change his or her own  sql password. The code is shown below.

When this executes, it does in fact change that users password, but it also throws the error:

ERROR[42000] [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot alter the login '<user>', because it does not exist or you do not have permission.

Has anyone seen this behavior before, and were you able to eliminate the error? The same command issued via SSMS works also works correctly but does not thow any error.

            dbconnect oConnection = new dbconnect();

            // change sql password for current user
            string strSql = "ALTER LOGIN " + Session["s_user"].ToString().Trim() + " WITH PASSWORD='" + ChangePassword1.NewPassword + "' OLD_PASSWORD='" + ChangePassword1.CurrentPassword + "'";
            OdbcCommand oCmd1 = new OdbcCommand(strSql, oConnection.Connection);
            try
            {
                oCmd1.ExecuteNonQuery();
            }
            catch(OdbcException oe)
            {
                 PasswordErrorDetails.Text = (oe.Message);
            }
            oConnection.dbdisconnect();
0
ablesonb
Asked:
ablesonb
  • 4
  • 2
1 Solution
 
jorgedeoliveiraborgesCommented:
display strSql on screen. Send the command to the database server thru «SQL Server Management Studio» within a DBA account, please.
0
 
ablesonbAuthor Commented:
I will as soon as the 1 day limit for password change times out.
0
 
ablesonbAuthor Commented:
I stumbled on the solution while getting more info for feedback. The sql command was generated correctly and ran without error when applied directly to sql via SSMS. However, an error in the C# .aspx page caused the ChangingPassword event to fire twice. The first time it changed the password, the second time failed because the old password no longer matched. This caused the permission error.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
ablesonbAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for ablesonb's comment http:/Q_27402776.html#37007458

for the following reason:

Debug code added to provide more info for this site highlighted the problem.
0
 
jorgedeoliveiraborgesCommented:
The post 36992928 is an invite to debug, isn´t it?
0
 
ablesonbAuthor Commented:
Yes, but it was only an invitation to check something that I had already said worked successfully.

'The same command issued via SSMS works also works correctly but does not thow any error.'

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now