SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Cross Database Query Permissions


Cross Database Query Permissions

Author
Message
Sioban Krzywicki
Sioban Krzywicki
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4212 Visits: 8096
I have multiple databases on the same server, let's call them Sales, Vehicle and Cheese.
In the databases are tables that I would like to call from the other databases. For example, Sales.dbo.Money, Vehicle.dbo.Wheels and Cheese.dbo.Delicious.

When I am in Sales and I try to run the query
SELECT * FROM Cheese.dbo.Delicious


I get
Msg 208, Level 16, State 1, Line 1
Invalid object name Cheese.dbo.Delicious



However, if I am in Cheese and I try to run the query
SELECT * FROM Sales.dbo.Money


I get the proper results of the query.

I cannot access any data in Cheese from other databases with a three part table name. I can access anything in Sales or Vehicle from any of the databases using a three part table name specification, including from Cheese.

I think I have a permissions problem, but I'm not sure where it is. My account is on the server, but not on any of the individual databases. Where should I be looking?

When I'm using a cross database query, it is using my permissions for both databases or some other specification.

If I set up a synonym in the Sales database for the table reference, for example
CREATE SYNONYM TastyCheese FOR Cheese.dbo.delicious


Is a different set of permissions needed? Is there a specific account that synonyms use?

I've never seen this error come up before for a simple same server, cross database query.

--------------------------------------
When you encounter a problem, if the solution isn't readily evident go back to the start and check your assumptions.
--------------------------------------
It’s unpleasantly like being drunk.
What’s so unpleasant about being drunk?
You ask a glass of water. -- Douglas Adams
Matt Crowley
Matt Crowley
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1049 Visits: 469
It is most likely that your login is not defined as a user in the Cheese database, or a member of a group that is defined as a user in the Cheese database. Can you run the following?
use Cheese


If not, then you are definitely not defined in the Cheese database.

To simplify permissions (and referential integrity, and recovery), have you considered moving the tables from the Cheese database into a central database as a schema, rather than as a standalone database?
Sioban Krzywicki
Sioban Krzywicki
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4212 Visits: 8096
Matt Crowley (1/21/2014)
It is most likely that your login is not defined as a user in the Cheese database, or a member of a group that is defined as a user in the Cheese database. Can you run the following?
use Cheese


If not, then you are definitely not defined in the Cheese database.

To simplify permissions (and referential integrity, and recovery), have you considered moving the tables from the Cheese database into a central database as a schema, rather than as a standalone database?


Got it, as it frequently is, the problem turned out to be a simple typo.

Thanks for the assistance!

--------------------------------------
When you encounter a problem, if the solution isn't readily evident go back to the start and check your assumptions.
--------------------------------------
It’s unpleasantly like being drunk.
What’s so unpleasant about being drunk?
You ask a glass of water. -- Douglas Adams
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search