Solved

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

Posted on 2012-12-24
10
791 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 142

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
 

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 142

Expert Comment

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

sa is the login, dbo is the user.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 142

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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now