Here is the scenario:
On a single server there are two databases:
DB1 = OLTP database for an application
DB2 = Audit Log Database
Cross database ownership is enabled
Both databases are marked as Trustworthy
There is an Active Directory Group used by the application to connect to the database and that group is assigned to a Database Role that exists in both databases. This role has the following permissons ONLY
Stored Procedure = Execute
Stored Procedure = View Definition
View = SELECT
Access to all other objects are denied.
Certain tables in DB1 need to be audited, and have triggers on them that detect changed values and write those values out to tables in DB2.
Tables and Triggers in DB1 are all in the dbo schema
Audit Log tables in DB2 are in the dbo schema
The Stored procedures in DB1 that actually perform the updates are in the ZBO schema, and are called from exposed procedures in the DBO schema.
This all works perfectly when I am logged in as me (SysAdmin) but when logged in as the application user all changes are applied correctly, and there are no errors, but the audit logs remain empty.
It makes no difference whether the trigger does a direct insert into the audit tables (using three-part naming of course) or calls a stored procedure in DB2 that does the insert. Nothing gets written if the user is a member of the application role.
I have tried explicitly granting SELECT/INSERT/UPDATE permissions on the tables in DB2 to the application role
I have tried explicitly setting the properties of the app role in DB2 (the log database) to dbo - still no good.
I even tried moving the audit tables back into the same database (i.e. DB1) and it still doesn't work!
I am guessing that I need some particular combination of settings here, but I can't figure out what that is.
Has anyone got any ideas?
If the insert failed I would expect an error to be raised, unless it is being trapped by a TRY/CATCH in the trigger and not being bubbled out to stop the auditable transaction. Can you post some trigger code representative of the logic and error handling?
When you say 'application role' do you mean an application role
or do you mean the User-defined Database Role the application is a member of?
To do cross-database calls transparently you would need to setup cross-database ownership chaining, else you could look into signing the triggers with certificates so the security context can be changed within them to a login capable of writing to the other database without elevating the permissions of the callers.
__________________________________________________________________________________________________There are no special teachers of virtue, because virtue is taught by the whole community. --Plato