Wednesday, April 12, 2017

“ Trigger has an Unresolved reference to User” but just in Visual Studio database project

Leave a Comment

I´m creating a database trigger in a database project in Visual Studio and that´s where I get the following error (and just in the trAudit_Transactions.sql file but not when I run it on the db server)

Trigger: [MYDB].[trAudit_Transactions] has an unresolved reference to User [MYDB_Audit].

and my trigger looks like this

CREATE TRIGGER [trAudit_Transactions] ON [MYDB].[TRANSACTION_WAIT] WITH EXECUTE AS 'MYDB_Audit'  -- the error comes from here FOR INSERT, UPDATE, DELETE  AS ... 

And since I can´t publish/build the solution (because of the error) I just comment out line nr 2 and create the script, uncomment the erroneous part and it runs just fine on the server.

Why/what is this? And just in Visual Studio? Everything works just fine when I change the published script and run it against the db.

The rest of the create is here

CREATE LOGIN   [MYDB_Audit]     WITH PASSWORD = N'xxx' CHECK_POLICY = OFF; CREATE USER    [MYDB_Audit]     FOR LOGIN     [MYDB_Audit]; CREATE ROLE    [db_mydb_audit]  AUTHORIZATION [dbo]; ALTER  ROLE    [db_mydb_audit]  ADD MEMBER    [MYDB_Audit]; GRANT CONNECT                   TO            [MYDB_Audit]; 

I have tried everything I can think of and searched everywhere without any luck.

What is going on here? What am I missing?

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment