Reputation: 893
Iam using sql server 2012 and visual studio 2017
Ihave created a data base project with target platform = sql server 2012 and made the following procedure
CREATE PROCEDURE [MySchema].[MyProcedure]
WITH ENCRYPTION
AS
BEGIN
SET NOCOUNT ON;
EXECUTE AS LOGIN = 'sa'
INSERT INTO [MySchema].[TableName]
(
Column1,
Column2
)
Values
(1,
2)
END
but when i build the project i got the following warning
[MySchema].[MyProcedure] has an unresolved reference to object [sa]
i searched and found some solutions suggest adding master as data base reference but it doesn't work so how to clear this warning please
Upvotes: 0
Views: 189
Reputation: 46233
The master database reference doesn't include logins. You can avoid the warning by adding a CREATE LOGIN sa...
. script to your project.
Be mindful that the actual sa
login may have been renamed so deploying logins will create a different login with the name sa
that isn't a sysadmin role member unless to add a ALTER SERVER ROLE sysadmin ADD MEMBER sa;
script too.
Personally, I would avoid EXECUTE AS LOGIN
entirely and use certificates to elevate permissions when needed. That is more secure as it avoids the need to grant IMPERSONATE
permissions.
Upvotes: 1