Here's a version that incorporates the Enterprise Libraries DAB and a couple other minor changes. Also, I don't see a point in returning a Boolean, since it's either going succeed or throw an exception.
public static void ChangeUsername(string oldUsername, string newUsername)
{
if (string.IsNullOrWhiteSpace(oldUsername))
{
throw new ArgumentNullException("oldUsername cannot be null or empty");
}
if (string.IsNullOrWhiteSpace(newUsername))
{
throw new ArgumentNullException("newUsername cannot be null or empty");
}
if (oldUsername.Equals(newUsername))
{
return;
}
Database db = DatabaseFactory.CreateDatabase();
using (DbCommand cmd = db.GetSqlStringCommand("UPDATE dbo.aspnet_Users SET UserName=@NewUsername, LoweredUserName=@LoweredNewUsername WHERE UserName=@OldUsername"))
{
db.AddInParameter(cmd, "@OldUsername", DbType.String, oldUsername);
db.AddInParameter(cmd, "@NewUsername", DbType.String, newUsername);
db.AddInParameter(cmd, "@LoweredNewUsername", DbType.String, newUsername.ToLower());
db.ExecuteNonQuery(cmd);
}
}