By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,812 Members | 875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,812 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Jan 17 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

Jan 17 '06 #2

P: n/a
set the dbtype to nVarChar with size of 128
"pa********@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

Jan 17 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.