/**********************************************************************/
/* UninstallProfile.SQL                                       */
/*                                                                    */
/* Uninstalls the tables, triggers and stored procedures necessary for*/
/* supporting the aspnet feature of ASP.Net                           */
/*
** Copyright Microsoft, Inc. 2002
** All Rights Reserved.
*/
/**********************************************************************/

PRINT '--------------------------------------------------'
PRINT 'Starting execution of UninstallProfile.SQL'
PRINT '--------------------------------------------------'
GO

-- In the area between the ASP.NET SPECIAL REGION "BEGIN" and "END" marker
-- comments, ASP.NET SQL Registration Tool will optionally:
-- 1. Replace the name of the database in all "USE" statements.
-- 2. Replace the value of the local variable @dbname
-- The replacement happens only in memory when the tool is running.

-- Inside such regions, user can only modify the name of the database.


-- Explicitly set the options that the server stores with the object in sysobjects.status
-- so that it doesn't matter IF the script is run using a DBLib or ODBC based client.
SET QUOTED_IDENTIFIER OFF -- We don't use quoted identifiers
SET ANSI_NULLS ON         -- We don't want (NULL = NULL) == TRUE
GO
SET ANSI_PADDING ON
GO

-- Telligent Systems
-- 
-- The following block is commented out to allow someone to install
-- member roles in a different database than wshadb
-- 
-- 
-- /* ASP.NET SPECIAL REGION BEGIN: DO NOT MODIFY THIS LINE */
-- USE wshadb
-- /* ASP.NET SPECIAL REGION END: DO NOT MODIFY THIS LINE */

--WSHA FIX
declare @command nvarchar(4000)
set @command = 'grant execute on [dbo].aspnet_Setup_RemoveAllRoleMembers to [' + user + ']'
exec (@command)
go
--WSHA FIX


IF EXISTS ( SELECT * FROM dbo.sysusers WHERE issqlrole = 1 AND name = N'aspnet_Profile_FullAccess'  ) BEGIN
  EXEC [dbo].[aspnet_Setup_RemoveAllRoleMembers] N'aspnet_Profile_FullAccess'
  EXEC sp_droprole N'aspnet_Profile_FullAccess' 
END      

IF EXISTS ( SELECT * FROM dbo.sysusers WHERE issqlrole = 1 AND name = N'aspnet_Profile_BasicAccess'  ) BEGIN
  EXEC [dbo].[aspnet_Setup_RemoveAllRoleMembers] N'aspnet_Profile_BasicAccess'
  EXEC sp_droprole N'aspnet_Profile_BasicAccess'
END      

IF EXISTS ( SELECT * FROM dbo.sysusers WHERE issqlrole = 1 AND name = N'aspnet_Profile_ReportingAccess'  ) BEGIN
  EXEC [dbo].[aspnet_Setup_RemoveAllRoleMembers] N'aspnet_Profile_ReportingAccess'
  EXEC sp_droprole N'aspnet_Profile_ReportingAccess'
END      

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[aspnet_Profile_GetProperties]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE [dbo].[aspnet_Profile_GetProperties]

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[aspnet_Profile_SetProperties]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE [dbo].[aspnet_Profile_SetProperties]

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[aspnet_Profile_GetProfiles]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE [dbo].[aspnet_Profile_GetProfiles]

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[aspnet_Profile_GetNumberOfInactiveProfiles]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE [dbo].[aspnet_Profile_GetNumberOfInactiveProfiles]

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[aspnet_Profile_DeleteInactiveProfiles]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE [dbo].[aspnet_Profile_DeleteInactiveProfiles]

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[aspnet_Profile_DeleteProfiles]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE [dbo].[aspnet_Profile_DeleteProfiles]

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[aspnet_Profile]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[aspnet_Profile]

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[vw_aspnet_Profiles]') AND OBJECTPROPERTY(id, N'IsView') = 1)
DROP VIEW [dbo].[vw_aspnet_Profiles]

GO

--WSHA FIX
declare @command nvarchar(4000)
set @command = 'revoke execute on [dbo].aspnet_Setup_RemoveAllRoleMembers from ' + user
exec (@command)
go
--WSHA FIX

PRINT '---------------------------------------------------'
PRINT 'Completed execution of UninstallProfile.SQL'
PRINT '---------------------------------------------------'
