locked
Change DB password using application doesn't work RRS feed

  • Question

  • I have a local database MyDB on MyLocalPCName, and I have a user set up as MyUser.  Using MS Server Mgmt Studio, I can log in as that user, and with the database set to MyDB, run the command:

    alter login MyUser with password = 'NewPW' old_password = "OldPW'

    It runs successfully, and then when I try to log in under the new password, it works.  (Then I change the password back to the old password.)

    Now I try to do the same thing from a .NET application and it does not work.  My connection string is:

    Data Source=MyLocalPCName;Initial Catalog=MyDB;User Id=MyUser;Password=OldPW;Connection Timeout=5

    and in the code, using embedded SQL, I issue the same Alter command within a Try block.  The code executes and no exception is thrown. 

    But then I cannot login to the database.  Not with the old pw, and not with the new pw.  Why am I seeing this behavior, and what can I do to successfully change the pw from within an application?  All my other queries in the app execute fine.

    Monday, August 18, 2014 9:40 PM

Answers

  • Sounds like you were successful in changing the password from the application. The only snag is that you don't seem to know what you changed it to...

    Since we don't see the code, we can't say what's wrong with it, but it seems that you don't form the SQL command correctly.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
    • Marked as answer by EJC651 Monday, August 18, 2014 11:19 PM
    Monday, August 18, 2014 9:48 PM

All replies

  • Sounds like you were successful in changing the password from the application. The only snag is that you don't seem to know what you changed it to...

    Since we don't see the code, we can't say what's wrong with it, but it seems that you don't form the SQL command correctly.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
    • Marked as answer by EJC651 Monday, August 18, 2014 11:19 PM
    Monday, August 18, 2014 9:48 PM
  • You are right again.
    Monday, August 18, 2014 11:18 PM