Link to home
Start Free TrialLog in
Avatar of frosty1
frosty1

asked on

Delete all asp.net users with applicationId = xx

how do remove all asp.net users where application id = xx



Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

There is no out-of-the-box way to do it, so you would need to write your own routine for doing it. Something like the following should work:
DECLARE @ApplicationName	NVARCHAR(256)
SET @ApplicationName = N'TestApplication'

DECLARE @ApplicationID	UNIQUEIDENTIFIER;
SELECT @ApplicationID = [ApplicationId] FROM [aspnet_Applications] WHERE [ApplicationName] = @ApplicationName;

DECLARE UserCursor CURSOR
	FOR SELECT [UserName] FROM [aspnet_Users] WHERE [ApplicationId] = @ApplicationID;

DECLARE @UserName NVARCHAR(256);
DECLARE @TableCount INT;

OPEN UserCursor;
FETCH NEXT FROM UserCursor INTO @UserName
WHILE (@@FETCH_STATUS = 0)
BEGIN

	EXEC [aspnet_Users_DeleteUser] @ApplicationName, @UserName, 8, @TableCount OUTPUT;

	FETCH NEXT FROM UserCursor INTO @UserName
END

CLOSE UserCursor;
DEALLOCATE UserCursor; 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of frosty1
frosty1

ASKER

thanks guys, actually both answered would do the trick. I selected that later as i'm comfortable in C# that SQL.