"Trigger has an unresolved user reference", but only in a Visual Studio database project

I am creating a database trigger on a database project in Visual Studio and this is where I get the following error (and only in the trAudit_Transactions.sql file, but not when I run its 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 cannot post / build the solution (due to error), I just comment out line nr 2 and create a script, uncomment the error part and it works fine on the server.

Why / what is this? And only in Visual Studio? Everything works fine when I modify the posted script and run it against the db.

The rest of the creation 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've tried everything I can think of and search everywhere with no luck.

What's going on here? What am I missing?

+3


source to share





All Articles