I am trying to remove/ drop a users permissions but i keep getting the following error:
The server principal “DevMe” is not able to access the database “CallManager” under the current security context.
My Stored proc to do this looks as follows:
USE [AuditIT]
GO
/****** Object: StoredProcedure [dbo].[AdminDevUserDelete] Script Date: 06/29/2012 08:54:27 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--alter table AdminLog add HostName varchar(128) NULL DEFAULT HOST_NAME()
ALTER PROCEDURE [dbo].[AdminDevUserDelete]
@SQLLoginName varchar(50)
AS
DECLARE @DatabaseName varchar(1000)
PRINT 'USE [master] DROP LOGIN [' + @SQLLoginName + ']'
EXEC ('USE [master] DROP LOGIN [' + @SQLLoginName + ']')
DECLARE CSDatabase CURSOR FOR
SELECT
[Name]
FROM
[Master]..SysDatabases
--WHERE
-- --[sid] = 0x01
-- [Name] NOT IN ('ReportSRV.Support','HelpDeskFacilities','QuestSoftware')
ORDER BY
dbid DESC
OPEN CSDatabase
FETCH NEXT FROM CSDatabase INTO @DatabaseName
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC ('SELECT [Name] FROM [' + @DatabaseName + ']..SysUsers WHERE [Name] = ''' + @SQLLoginName + '''')
IF @@RowCount > 0
BEGIN
PRINT 'USE [' + @DatabaseName + '] DROP USER [' + @SQLLoginName +']'
EXEC ('USE [' + @DatabaseName + '] DROP USER [' + @SQLLoginName +']')
END
FETCH NEXT FROM CSDatabase INTO @DatabaseName
END
CLOSE CSDatabase
DEALLOCATE CSDatabase
Could someone please explain how i could fix this problem?