Tuesday, February 14, 2012

Change Password

Hello,

I'm trying to change the password of a user.

This is my code:

Dim conn As New ServerConnection("STATION01\SQLEXPRESS", wContainer.Username, wContainer.Password)

Dim myServer As New Server(conn)

Dim myUsername As String = TextBox2.Text.Trim

Dim myPassword As String = TextBox3.Text.Trim

If myServer.Logins.Contains(myUsername) And myUsername <> String.Empty Then

Dim db_login As New Login(myServer, myUsername)

db_login.ChangePassword(myPassword)

db_login.Alter()

End If

It doesn't work.

The way your instantiating your login object is where the problem is:


Dim objLogin As Login
Dim colLogin As LoginCollection

colLogin = srv.Logins
objLogin = colLogin.Item("fred")
objLogin.ChangePassword("meow")
objLogin.Alter()

This works (but is a really bad example for proper login/password values.)

|||Thanks.

No comments:

Post a Comment