Max Isaev
Max Isaev

Reputation: 1

VERY strange behavior of sys.dm_hadr_database_replica_cluster_states in a SQL Job

How to call DMV sys.dm_hadr_database_replica_cluster_states inside SQL job?

Code is very simple in step:

CREATE TABLE #D (DB sysname);
INSERT #D
select database_name
from sys.dm_hadr_database_replica_cluster_states;
 

But when job starts, it throws error: Msg 15562, Sev 16, State 2, Line 3 : The module being executed is not trusted. Either the owner of the database of the module needs to be granted authenticate permission, or the module needs to be digitally signed. [SQLSTATE 42000]

WHY??
Owner of the job - sa Service account of SQL Agent - has role sysadmin on the server.

I broke my head. Google didn't help me at all... Any crazy ideas are welcome!

Upvotes: 0

Views: 289

Answers (1)

Max Isaev
Max Isaev

Reputation: 1

I found medicine:

ALTER DATABASE master SET TRUSTWORTHY ON

Thanks to all, guys!

Upvotes: 0

Related Questions