0

I'm trying to change passwords of SQL server logins, but the Passwords just won't change. This is what I have:

SqlCommand query = new SqlCommand("ALTER LOGIN @login WITH PASSWORD = '@Pwd'", con);
query.Parameters.Add("@login", SqlDbType.NVarChar, 60).Value = login;
query.Parameters.Add("@Pwd", SqlDbType.NVarChar, 20).Value = _newPwds[login];
query.Prepare();
query.BeginExecuteNonQuery();

I don't get any error messages back from the SQL Server or debugging (Or I don't know how to get them). The Connection is correct and I have the rights to Change Passwords on the Server (Application is running with Integrated Security).

Thanks for your help.

3
  • @mason Thanks, didn't know that. I changed it and now I get "Incorrect Syntax near '@login'". Commented Sep 18, 2017 at 15:43
  • See this question for an example of using parameters with an alter login statement. Commented Sep 18, 2017 at 15:48
  • @mason Thanks! I'll test that on Thursday, but I think this will do. Could you add this to your answer? Then I would mark it as the right answer after I tested it. Commented Sep 18, 2017 at 16:20

1 Answer 1

1

You are using an asynchronous method BeginExecuteNonQuery to execute the query, so you haven't captured it. Given you probably didn't want to go async, try using ExecuteNonQuery instead:

query.ExecuteNonQuery();

Plus you can't use parameters in an ALTER LOGIN statement, see this question.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.