Solved

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

Posted on 2012-12-24
10
849 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
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 

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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
This query failed in sql 2014 5 38
SQL Server 2012 r2 - Sum totals 2 31
Disable TLS1.0 on Win 2012 server 7 61
T-SQL: I need to add an index on a field 5 23
I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…

749 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