Menu
Reply To Topic Topic: Useful DNN SQL Scripts
:
Posted By Deleted User on 10/10/2013 1:51 PM
Change a Username If you are going to make this repeatable, you might want to wrap the logic in a transaction. You wouldn't want the two tables to be out of sync. Here is a sample as series of T-Sql statements. Run this from the SQL tab in the host menu or from SQL Server Management Studio. Should be easy to convert to a stored proc: declare @oldName nvarchar(128) declare @newName nvarchar(128) declare @error_var int, @rowcount_var int declare @newNameCount int select @oldName = 'johndoe1' select @newName = 'johndoe2' 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 - Recycle the Application Pool after running this procedure. This script was borrowed from an entry by Michael Levy in the following DNN Forum entry: http://www.dnnsoftware.com/forums/forumid/36/threadid/27822/scope/posts Thank you Michael Levy
Username:
Security Code:
CAPTCHA image
Enter the code shown above in the box below.
Subject:
RE: Useful DNN SQL Scripts
Message:
Smilies

Submit

Cancel
Subscribe:
Topic Review