Home All Groups Group Topic Archive Search About

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

Author
17 Jan 2006 9:15 PM
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

Author
17 Jan 2006 9:26 PM
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.
Author
17 Jan 2006 9:43 PM
KMSBest
set the dbtype to nVarChar with size of 128


Show quoteHide quote
"partybo***@hotmail.com" wrote:

> 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
>
>