Removing missing application references from an ASP.NET SQL database?

Creation of my first site using the login / membership system introduced in ASP.NET (v4).

So far so good, use web.config to point it to the remote SQL server and it works.

What I did not do initially was to specify the "application name" for the membership provider, so when viewing tables on the SQL server it appears as "/".

I updated the web.config file and added the Membership and Provider sections necessary to assign the name assigned to it and ran the ASP.NET configuration wizard to reinitialize the user database.

In the SQL server, the application now displays its name and new GUID and works as expected.

My question is, is there an automated way to get rid of all (now unnecessary) records associated with the "old site" from various ASP.NET SQL tables, or am I forcing it to be done manually?

If I need to do this manually, does anyone know about the laid out set of procedures so that all links are deleted from the database?

+5
source share
1 answer

I used this script on my development machine without any problems in the past. I can’t say that I ever really traveled to the city with a membership provider, so I only ever had data in the users and roles table, but I think this script should put everything in order.

, , .

DECLARE @APPID UNIQUEIDENTIFIER 

--Change the application id to the app you want to clear out 
SET @APPID = 'bb5f1064-062d-4a21-875c-dc15c1e9ec27'

delete from aspnet_Membership Where UserId in ( Select UserId From aspnet_Users Where ApplicationId = @APPID)
delete from aspnet_PersonalizationPerUser Where PathId in ( Select PathId From aspnet_Paths Where ApplicationId = @APPID)
delete from aspnet_PersonalizationAllUsers Where PathId in ( Select PathId From aspnet_Paths Where ApplicationId = @APPID)
delete from aspnet_Paths Where ApplicationId = @APPID
delete from aspnet_PersonalizationPerUser Where UserId in ( Select UserId From aspnet_Users Where ApplicationId = @APPID)
delete from aspnet_Profile Where UserId in ( Select UserId From aspnet_Users Where ApplicationId = @APPID)
delete from aspnet_UsersInRoles Where RoleId in( Select RoleId from aspnet_Roles Where ApplicationId = @APPID)
delete from aspnet_Roles Where ApplicationId = @APPID
delete from aspnet_Users Where ApplicationId = @APPID
delete from aspnet_Applications Where ApplicationId = @APPID
+10

All Articles