Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / General / Security / October 2005

Tip: Looking for answers? Try searching our database.

DELETE permission denied problem when using a stored proc to delet

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Bucknell - 12 Oct 2005 08:10 GMT
I'm using a stored proc to delete a record in two tables (in two different
databases) and I keep receiving “Error Number: 229 -- Error State: 5 -- Error
Message: DELETE permission denied on object 'ewBehaviour', database
'eWorkSpaceV5', owner 'dbo' ”.  The stored proc works for me (as sysadmin for
the server), but won’t work for any other user.  I’ve tried giving a user
db_owner access for both the databases but I still receive the error.

Below is the stored proc:

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

ALTER    PROCEDURE dbo.spWEB_Delete_Detention
@DetentionID as int

AS
    SET XACT_ABORT ON

    DECLARE @BehaviourId as int

    IF NOT EXISTS
    (
        SELECT DetentionID
        FROM  DC_Detentions
        WHERE DetentionID=@DetentionID
    )
    BEGIN
        RAISERROR ('Detention does not exist in DC_Detention ',16,1)
        RETURN -1
    END

    IF NOT EXISTS
    (
        SELECT Id
        FROM eWorkSpaceV5.dbo.ewBehaviour
        WHERE ID =
        (SELECT Link
        FROM  DC_Detentions
        WHERE DetentionID=@DetentionID)
    )   
    BEGIN
        RAISERROR ('Behaviour entry does not exist in ewBehaviour',16,1)
        RETURN -1
    END
   
    SELECT @BehaviourId=Link
    FROM  DC_Detentions
    WHERE DetentionID=@DetentionID

    BEGIN TRANSACTION
    print 'Begin Transaction'
    print 'Try Delete DC_Detentions'
    DELETE FROM DC_Detentions
    WHERE     (DetentionID = @DetentionID)
    IF @@ERROR<>0 or @@ROWCOUNT<>1
    BEGIN
        ROLLBACK TRANSACTION
        RAISERROR('Could not delete Detention from DC_Detention',16,1)
        print 'Delete from DC_Detention failed'
        RETURN -1       
    END
   
    print 'Try Delete eWorkSpaceV5 ewBehaviour'
    DELETE FROM eWorkSpaceV5.dbo.ewBehaviour
    WHERE     (Id = @BehaviourId)
    IF @@ERROR<>0 or @@ROWCOUNT<>1
    BEGIN
        ROLLBACK TRANSACTION
        RAISERROR('Could not delete Detention into ewBehaviour',16,1)
        print 'Delete from ewBehaviour failed'
        RETURN -1       
    END

    COMMIT TRANSACTION
    RETURN 0

    SET XACT_ABORT OFF

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
Jens - 12 Oct 2005 08:25 GMT
As long as you dont activate ownership chain (as I assume that you are
deleting data in a different database) this won´t work. Ownerchip
chains is disabled by default since SP3.

Look for cross database ownership chain in BOL or for the thread:

http://groups.google.de/group/microsoft.public.sqlserver.programming/browse_frm/
thread/4b86a2ccefd974af


HTH, JEns Suessmeyer.
Chris Bucknell - 13 Oct 2005 00:09 GMT
Thanks for the points, I didn't have chaining enabled.  I have enabled
chaining but I'm still getting the same error of DELETE permission denied
when I try and delete the data from the second database.

> As long as you dont activate ownership chain (as I assume that you are
> deleting data in a different database) this won´t work. Ownerchip
[quoted text clipped - 5 lines]
>
> HTH, JEns Suessmeyer.
Dan Guzman - 13 Oct 2005 00:56 GMT
Did you peruse the article in the link Jens posted?  In addition to enabling
the 'db chaining' database option (or cross-database chaining server option)
the databases need to have the same owner so that the dbo-owned object
ownership chain is unbroken.  You can use sp_changedbowner to make the
database owners the same.  For example:

USE MyDB1
EXEC sp_changedbowner 'SomeLogin'
USE MyDB2
EXEC sp_changedbowner 'SomeLogin'
GO

Signature

Hope this helps.

Dan Guzman
SQL Server MVP

> Thanks for the points, I didn't have chaining enabled.  I have enabled
> chaining but I'm still getting the same error of DELETE permission denied
[quoted text clipped - 9 lines]
>>
>> HTH, JEns Suessmeyer.
Chris Bucknell - 13 Oct 2005 01:10 GMT
Thanks for the threads you suggested, I sorted the problem - the two
databases had different owners, now thats sorted it works fine.

> Thanks for the points, I didn't have chaining enabled.  I have enabled
> chaining but I'm still getting the same error of DELETE permission denied
[quoted text clipped - 9 lines]
> >
> > HTH, JEns Suessmeyer.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.