Using SP_Password with VB.NET but keep getting "old (current) password incorrect for user"

P

partybob99

I am trying to call SP_Password from some vb.net code. This should be
very straight forward but no matter what I do, I keep getting errors.

Here is the code
strConnectString = "Data Source=" + strServer + ";Initial
Catalog=master;user id=" + strID + ";password=" + strOldPass + ";"

Conn.ConnectionString = strConnectString
Conn.Open()

cmd.Connection = Conn
cmd.CommandText = "SP_Password"
cmd.CommandType = CommandType.StoredProcedure

cmd.Parameters.Add("@old", SqlDbType.Char, 20)
cmd.Parameters.Add("@new", SqlDbType.Char, 20)
cmd.Parameters.Add("@loginame", SqlDbType.Char, 20)
cmd.Parameters("@old").Value = stroldPass
cmd.Parameters("@new").Value = strNewPass

intReturn = cmd.ExecuteNonQuery()
Conn.Close()

This throws an sql exception every time that says:
Current (old) password is not correct. Password not changed.

I was able to determine that the error that is being raised is 15211.

Here is what I know.
1) This function works from query analyzer when I log in using the ID
and password that I'm trying to change and run sp_password directly.
2) I know the that I am logging in with the correct ID successfully
because if I was not, I get a different sql exception saying so.
3) I've tried using SQLDBTYPE.Nchar instead of char, no effect.
4) Leaving loginname NULL is the desirable thing to do if you are
trying to change your own ID. Only a user with sysadmin role can use
the loginame parameter.
5) I've tried using NChar instead of Char - no effect.

I saw that this procedure cannot be called from a user transaction, but
I dont think this applies here.

Thanks in advance to anyone who can help because I've been trying to
figure this one out for 6 hours now...
Bob
 
C

cbrown

You may want to try ALTER LOGIN

ALTER LOGIN Victoria WITH PASSWORD = 'B3r1000d#2-36'

This sets the new password without knowing the old one. But you must
have the correct privelidges to do so.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top