?
Solved

how to execute a stored procedure like  sysadmin or workaround for checking mirroring

Posted on 2012-12-24
10
Medium Priority
?
990 Views
Last Modified: 2013-01-03
Hello,

I try to create a stored prod for checking db mirroring without be sysadmin :
create procedure check_mirror WITH EXECUTE AS ...  AS

set nocount on;
SELECT a.name +'|'+ CAST(isnull(b.mirroring_role,'') AS varchar(15)) +'|'+ CAST(isnull(b.mirroring_partner_instance,'') AS varchar(15))from sys.databases a INNER JOIN sys.database_mirroring b ON a.database_id=b.database_id where mirroring_role is null or mirroring_role=1 or mirroring_role=2

Thanks
bibi
0
Comment
Question by:bibi92
  • 5
  • 4
10 Comments
 
LVL 18

Expert Comment

by:x-men
ID: 38718605
WITH EXECUTE AS OWNER
0
 

Author Comment

by:bibi92
ID: 38718852
I have tried this but it doesn't work. Thanks bibi
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38719212
you need to create procedure being sysadmin
create procedure check_mirror WITH EXECUTE AS SA 
AS
 ... 

Open in new window

and grant the permissions of the procedure to the user that needs to call this procedure.

if this does not work, what error do you get?
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:bibi92
ID: 38721397
Hello,

The error is Msg 15151, Level 16, State 1, Procedure test, Line 3
Cannot execute as the user 'SA', because it does not exist or you do not have permission.
But I try to create the procedure with sysadmin account.

Thanks

Regards

bibi
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38721425
sorry:
AS DBO

sa is the login, dbo is the user.
0
 

Author Comment

by:bibi92
ID: 38721443
Thanks I have tried with dbo but it doesn't work. There is no error but I can't query the sys.database_mirroring.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38721525
permissions requirments for sys.database_mirroring
http://msdn.microsoft.com/en-us/library/ms178655.aspx
0
 

Author Comment

by:bibi92
ID: 38721612
Yes, thanks, I know that but I search a workaround.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 38721663
the only workaround is this:
* create a sql agent job, unscheduled
* instead of your current procedure, you could request the above job to be started sp_start_job

that's what I do to give "permissions" to users that they should not have directly
0
 

Author Closing Comment

by:bibi92
ID: 38740683
Thanks bibi
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question