views:

112

answers:

1

Note: This is a community wiki entry and is mainly to document a problem together with its solution. I was hardly able to find information on the net to solve this. Hope it helps someone!


I have a SQL-Server 2005 DB with the data tables being on the dbo schema. For a new component on the project, I created a new data access layer (using NHibernate) and to nicely capsule this, I created a new schema.

For all the objects I needed, I created a View:

myschema.ViewTable1 myschema.ViewTable2 etc. And granted select permission.

Now, when I tried to access these views by a user that only had select permissions on the views but not the underlying table with NHibernate, I got:

The SELECT permission was denied on the object 'dbo.Table1', database 'TestDB', schema 'dbo'.

According all the documentation, this should be possible. Even more strangely, the SQL did work executed in Management Studio as a plain select. But if I executed it with exec sp_executesql as NHibernate does it, it broke with the same exception.

After a long time searching I finally found this question here on StackOverflow. The added Update gave the clue:

My new schema myschema was owned by my windows user and not by the dbo!

After changing the schema owner to dbo and recreation of all the myschema objects (Yes, this is required!) things start to work as expected!

Hope this helps someone.

+1  A: 

Solution:

Make sure your schemas are owned by the same role!

Dominik Fretz