Update the if error section to retry after waiting for 1000ms, then attempt the request again, for example replace:
In order to fix this bug you can simply run this command on the effected database after you have used the backup (sql2000) / restore sql2005/2008) or detach attach methods.
command to run:
Replace "dbusername" with the problem user account. both should be the same.
This will remove the ghost user from the sql 2000 server and replace it with the new user on your sql 2005 / 2008 server. Be sure to have the user created before running this command.
Errors associated with this are as follows:
"login name must be specified Database user"
"The database principal owns a schema in the database, and cannot be dropped"
"user group or role already exists in the current database"
"can't delete sql user in database"