MSSQL error "Cannot find the object XXX because it does not exist or you do not have permissions"

1 minute read

This error can be confusing:

1Cannot find the object "XXX" because it does not exist or you do not have permissions
Especially when the table definitely exists and the user does have read/write permissions. Especially when it happens in an application which uses an ORM and you do not really control what SQL is actually sent to the DB.

It took me a while to profile queries and understand that the root cause was this statement:

1SET IDENTITY_INSERT "XXX" ON;

It was ORM-generated and was present only in particular cases which made debugging even harder. This is not obvious but SET IDENTITY_INSERT command actually requires ALTER permission. INSERT is not enough for it.

A similar issue reported at StackOverflow