Kaikus
Kaikus

Reputation: 1095

Grant permission for a view that uses tables form other databases

I know this question is repeated (Grant Select on a view not base table when base table is in a different database), but I have tried the proposed solution, without any luck.

My idea is grant limited access to data in certain databases through an intermediate database in which I create views. I do this to avoid granting specific permission on external tables every time I create a view. This is what I do:

ALTER DATABASE Database_A1 SET DB_CHAINING ON;  
ALTER DATABASE Database_A2 SET DB_CHAINING ON;
SELECT is_db_chaining_on, name FROM sys.databases;

Is there something I'm doing wrong?. I thin I have followed the indications stated in:

Ownership Chaining

cross db ownership chaining Server Configuration Option

Enabling Cross-Database Access in SQL Server

Upvotes: 0

Views: 2760

Answers (2)

Dan Guzman
Dan Guzman

Reputation: 46193

For dbo-owned objects, the database owners need to be the same to maintain an unbroken ownership chain. Make sure the databases have the same owners and use ALTER AUTHORIZATION ON DATABASE::YourDatabase TO YourDbOwner; to remediate. For objects in other schemas, the schema owner in each database needs to map to the same login.

Users also need an account in each database accessed (unless the guest user is enabled). However, no permissions need be granted on indirectly referenced objects.

Upvotes: 1

Wouter
Wouter

Reputation: 2976

You need to create the user in the other database (without granting any rights).

USE [DATABASE_A2]
GO
CREATE USER [User_B] FOR LOGIN [User_B]
GO

Upvotes: 1

Related Questions