Cross Database Query Permissions

  • 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

  • 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?

  • 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

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply