Re: one SQL DB getting info from another - user setup?

From: Dan Guzman (danguzman_at_nospam-earthlink.net)
Date: 06/12/03


Date: Wed, 11 Jun 2003 21:01:43 -0500


In order for a user to select from a view without permissions on the
referenced tables, the ownership chain needs to be unbroken. This means
that all of the objects involved need to have the same owner. This is
pretty straightforward when all of the objects are in the same
database - the owners are the same as long as the owner names are the
same.

This is a little tricky with inter-database object references. The
owning users must map to the same login in order for the ownership chain
to be unbroken. If your objects are owned by 'dbo', all 3 databases
need to have the same owner so that the 'dbo' user maps to the same
login. It appears from your narrative that the Main and DB1 databases
have the same owner but DB2 has a different database owner. You can
verify this with sp_helpdb:

EXEC sp_helpdb 'Main'
EXEC sp_helpdb 'DB1'
EXEC sp_helpdb 'DB2'
GO

You can then use sp_changedbowner so that the owner of all 3 databases
is the same:

USE DB2
EXEC sp_changedbowner 'YourCommonDatabaseOwner'
GO

Note that cross-database ownership chaining is a configurable option in
SQL 2000 SP3 and is turned off by default. You can enable it for
selected databases with sp_dboption (like the example below) or via
Enterprise Manager. Alternatively, you can turn it on at the server
level with sp_configure 'Cross DB Ownership Chaining'. In either case,
you should turn on cross-database chaining only if you fully trust
members of the db_owner and db_ddladmin roles.

EXEC sp_dboption 'Main', 'db chaining', true
EXEC sp_dboption 'DB1', 'db chaining', true
EXEC sp_dboption 'DB2', 'db chaining', true
GO

See the SQL Server 2000 SP3 Books Online
<"adminsql.chm::/ad_config_8d7m.htm"> for more information.

-- 
Hope this helps.
Dan Guzman
SQL Server MVP
-----------------------
SQL FAQ links (courtesy  Neil Pike):
http://www.ntfaq.com/Articles/Index.cfm?DepartmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
-----------------------
"Pete Ruby" <pete.ruby@carris.net> wrote in message
news:Oulu5hCMDHA.2480@TK2MSFTNGP10.phx.gbl...
> I have 3 SQL DB's.  The first one, called "Main", has a procedure that
pulls
> tables from our accounting package into the Main DB.  In doing so, it
> deletes the old tables, and recreates the new ones.  This procedure
runs
> nightly.  One of the tables it updates is called ITEMMAST.
>
> I have 2 other databases, call them DB1 and DB2.  They are both used
in
> separate web based apps.  Both have views that reference
Main.ITEMMAST.  DB1
> has user assigned to it called (you guessed it) USER1; DB2, USER2.
Both
> users are SQL type users, listed in the Security\Logins folder in SQL,
as
> Standard, with Permit access, with DB1, DB2 as their Default database.
They
> both have no server roles, and both have acess to their own DB, and
Main,
> with Public Roles.
>
> In the permissions for Main, USER1 and USER2 are listed, but have NO
> permissions set  (all option boxes are BLANK) for any of the tables in
Main,
> including ITEMMAST.  DB1 and USER1 run fine w/out having any
permissions set
> for ITEMMAST.  DB2 and USER2 have to have the "SELECT" option for
ITEMMAST
> selected to be able to run the associated views in DB2.
>
> The problem is when we run the procedure to update that table, the
> permissions are also lost.  i realize we can change the procedure to
just
> delete the records and then append....
>
> The real question is:  does USER1 and USER2 need specific permision to
> ITEMMAST?  If so, any ideas why USER1 has no problems running views
from DB1
> that reference ITEMMAST?
>
> Thanx
> Pete
>
>
>
>


Relevant Pages

  • Re: object level permissions being lost when migrating
    ... I am talking about SQL Logins, ... can go to the object and see that user X has permissions XYZ on that object, ... I then restored the databases and re-synched the users via the ...
    (microsoft.public.sqlserver.security)
  • Re: Stored Procedures and Security
    ... databases are owned by different people. ... >>I cannot only give EXEC permissions to a login on my SQL ... > the SELECT and UPDATE commands that are executed in the SP! ...
    (microsoft.public.sqlserver.programming)
  • Re: user defined Role - HELP
    ... exec rights on that sp. ... "Tom Moreau" wrote: ... are you using SQL 2000 or SQL 2005? ... permissions on the underlying table. ...
    (microsoft.public.sqlserver.security)
  • Re: Permission denied in table yet allowed access in Sproc but still no access
    ... Dynamic SQL breaks the ownership chain so permissions on the referenced ... databases, both databases need to have the same owner and cross-database ... SQL Server MVP ... >> I have a table which I am denied access but given the correct permission ...
    (microsoft.public.sqlserver.programming)
  • Re: Controlling Access to data from multiple databases
    ... this doesn't work since within the body of the stored procedure it reaches ... procedure fails on permissions. ... read only permission to all databases my stored procedure depends on. ... Links for SQL Server Books Online: ...
    (microsoft.public.sqlserver.security)