• Rechana Rajan - Monday, January 23, 2017 5:59 AM

    John Mitchell-245523 - Monday, January 23, 2017 3:03 AM

    Since all schemas in question are owned by the user dbo, you shouldn't have a problem with ownership chaining.  I recreated what I think your database looks like with the following code:
    create schema RRN authorization dbo

    create table RRN.Asettings (oid int)
    create table RRN.BTType (oid int)
    create table RRN.CSHistory (sId int)
    create table dbo.CB (MainProfileID int)
    create table RRN.Void (VoidID int)
    GO

    create login Test with password = 'xxxxxxxxx'
    create user Test from login Test
    GO

    CREATE VIEW [dbo].[View_1]
    AS
    SELECT RRN.ASettings.oid AS Expr1, RRN.BTType.oid, RRN.CSHistory.sId, dbo.CB.MainProfileID, RRN.Void.VoidID
    FROM RRN.ASettings INNER JOIN
    RRN.BTType ON RRN.ASettings.oid = RRN.BTType.oid CROSS JOIN
    RRN.CSHistory CROSS JOIN
    dbo.CB CROSS JOIN
    RRN.Void
    GO

    grant select on dbo.view_1 to Test

    execute as user = 'Test'
    select * from dbo.View_1
    revert

    The SELECT statement returned a result set (empty of course, but a result set nevertheless) and there was no error.  The only thing I can think of is that you have a case-sensitive database, because your view is called View_1 but you granted permission on view_1.  What do you get if you run this?
    SELECT DATABASEPROPERTYEX('TEST_DB','Collation')

    John

    Thanks a lot for the support.

    Query gave  SQL_Latin1_General_CP1_CI_AS

    When i tried to give Grant select on dbo.view_1 to Test got below message.

    Cannot grant, deny, or revoke permissions to sa, dbo, entity owner, information_schema, sys, or yourself.
    What i observed now is very strange that when i connect using the Login Test and access the view from SSMS i can see the result from from SSMS i am getting error.

    use Test
    select * from dbo.View_1

    Msg 916, Level 14, State 1, Line 3
    The server principal "TEST" is not able to access the database "Test" under the current security context.

    I'm quite confused now.  I thought you'd already granted Test SELECT on the view?  I'm also not clear on what the names of the database and the user are.  But it looks as if Test is the owner of View_1, even though the query results you posted earlier show that View_1 is owned by the schema owner.  Please will you post the results of this query:
    SELECT
         class_desc
    ,    USER_NAME(grantee_principal_id) AS Grantee
    ,    permission_name
    ,    state_desc
    ,    OBJECT_NAME(major_id) ObjectName
    ,    OBJECT_SCHEMA_NAME(major_id) InSchema
    ,    minor_id
    FROM sys.database_permissions
    WHERE major_id >= 0
    AND (OBJECT_NAME(major_id) IN ('Asettings','BTType','CSHistory','CB','Void')
    OR USER_NAME(grantee_principal_id) = 'Test')

    John