YAFLogo

67RSSS
  • 67RSSS
  • 100% (Exalted)
  • YAF Commander Topic Starter
13 years ago
Been a while since I needed help, YAF has been going strong for over a year now (link ). I have a user that would like to change his user name as he sold the car he named himself after. I found the following SQL code for updating the database for the DNN stuff:

_________________________________________________

declare @oldName nvarchar(128)

declare @newName nvarchar(128)

declare @error_var int, @rowcount_var int

declare @newNameCount int

select @oldName = 'jsmith'

select @newName = 'johndoe'

begin transaction

select @newNameCount = count(*)

from Users

where Username = @newName

if @newNameCount > 0

begin

RAISERROR('Username already exists. @newName=%s', 10, 1, @newName)

ROLLBACK TRANSACTION

RETURN

end

update Users

set Username = @newName

where Username = @oldName

SELECT @error_var = @@ERROR, @rowcount_var = @@ROWCOUNT

IF @rowcount_var <> 1 OR @error_var <> 0

BEGIN

RAISERROR('Could not Update User.Username. @oldName=%s', 10, 1, @oldName)

ROLLBACK TRANSACTION

RETURN

END

update aspnet_Users

set

Username = @newName,

LoweredUserName = LOWER(@newName)

where LoweredUserName = LOWER(@oldName)

SELECT @error_var = @@ERROR, @rowcount_var = @@ROWCOUNT

IF @rowcount_var <> 1 OR @error_var <> 0

BEGIN

RAISERROR('Could not Update aspnet_Users.Username. @oldName=%s', 10, 1, @oldName)

ROLLBACK TRANSACTION

RETURN

END

Commit transaction

go

__________________________________________

...and it works great. I entered it in the SQL window in DNN under the host account. Unfortunately it did not change the user name in the YAF database. Remembering that I am no programmer, could someone enlighten me on what need to be added to the script above? The red bits are all that change, so I am hoping to leave myself a text doc with it in it so I can call it up whenever someone wants to change their username. THANKS!!!!


Visit our site at www.northstarcamaroclub.com.
Sponsor
67RSSS
  • 67RSSS
  • 100% (Exalted)
  • YAF Commander Topic Starter
13 years ago
Nevermind. I just go into the admin on YAF and change the user name...
Visit our site at www.northstarcamaroclub.com.
Mek
  • Mek
  • 100% (Exalted)
  • YAF Developer
13 years ago
:-)

Note: from 1.93 onwards now; you need to be alot more careful with renaming. Roles definately isn't possible anymore (through no fault of our own).

Makes me think that Display Name is a much better way to go.


UserPostedImage

"It's a case of RTFM.. the only problem being we don't have a manual!"

When I post FP:Mek in a topic, I'm leaving my footprint there so I can track it once I get into coding/supporting. (Yes I stole this off Ederon 🙂 )

Zero2Cool
9 years ago
Originally Posted by: 67RSSS 

Nevermind. I just go into the admin on YAF and change the user name...

I tried changing a user name but ...

Username:

Cannot be modified.

bbobb
  • bbobb
  • 100% (Exalted)
  • YAF Developer
9 years ago
Hi, Kevin. No need in necroposting.:cheesy:

User names should not be changed at all, because of multiple reasons.

By the reason DisplayName was introduced at some point.

Zero2Cool
9 years ago
Originally Posted by: bbobb 

Hi, Kevin. No need in necroposting.:cheesy:

User names should not be changed at all, because of multiple reasons.

By the reason DisplayName was introduced at some point.

lol I try not to create threads of subjects already started.

Personally, I don't like messing with the UserName changes because of the Membership stuff, but I'd rather assume that risk than having multiple people posting under the same DisplayName or have other login related issues when they can't remember their login because their DisplayName is now different.

Edit, Your display name is already registered. Whew! So there will NOT be two "Kevin" posting. That is good. I still don't like not being able to change the UserName though! 😛

JP
  • JP
  • 100% (Exalted)
  • YAF Leader
9 years ago
I've had several requests for this, and I do it in the db directly... Have not enabled the "DisplayName" option so the username is really the username...

In the yaf_prov_Membership table, I change the Username & UsernameLwd to the new user name, and in the yaf_User table I change the Name & DisplayName... Has worked well so far, since the user GUID remains he same and that's what ASP.Net Membership cares about...

The same procedure is applied to email changes too, since it doesn't work for a user to change the email in his/hers profile directly... Ie - edits in the same db tables, but the email fields...


He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Old Chinese Proverb]
francoz
  • francoz
  • 82.4% (Honored)
  • YAF Lover
9 years ago
Step by step guide.

Launch these queries from SQL Server Management Studio:

Use yafnet

select * from yaf_User where Name like '%nametobechanged%'

Take note of the UserID, let us say it is 123

update yaf_User set Name = 'newnameofchoice' where UserID = 123

update yaf_User set DisplayName = 'newnameofchoice' where Name = 'newnameofchoice'

select * from yaf_prov_membership where Username like '%nametobechanged%'

Take note of the email, let us say it is user@mail.com

update yaf_prov_Membership set Username = 'newnameofchoice' where email = 'user@mail.com'

update yaf_prov_Membership set UsernameLwd = 'newnameofchoice' where email = 'user@mail.com'