August 29, 2007 at 1:08 pm
I have stored procedure that selects from master.dbo.SysProcesses to determine if any other users are connected to the application. It works fine in SQL 2000 but in SQL 2005 it only returns the user executing the stored procedure as the result.
I know you can grant VIEW
Is there any suggestion on how to make this work properly on SQL 2005?
Thanks,
Daniel
August 30, 2007 at 1:41 am
You can create a stored procedure with "execute as 'dbo'" like:
CREATE PROCEDURE foo2 WITH EXECUTE AS 'dbo' AS SELECT * FROM master.dbo.sysprocesses GO
You can grant execute to these to a user bar (CREATE USER bar WITHOUT LOGIN) :
GRANT EXECUTE TO foobar
Note that if bar executes the query now it will return only the single process, but you can then set the trustworthiness property on:
ALTER DATABASE foo2 SET TRUSTWORTHY ON
After this all the items are returned from SysProcesses.
Also, SysProcesses is depricated. In the future you should have a look at: sys.dm_exec_connections, sys.dm_exec_sessions, and sys.dm_exec_requests. These you can access from within the same database, and you may not need to set the the trustworthiness on your database.
Regards,
Andras
September 4, 2007 at 4:50 pm
Thanks for your help. I did have to add one additional step.
1. ALTER AUTHORIZATION ON DATABASE::dbname TO sa;
The database owners must match between the Master database and the user database.
Thanks,
Daniel
September 5, 2007 at 8:57 am
Also, you still would need to set up trustworthiness if you use sys.dm_exec_sessions instead of sysprocesses.
But will use this instead of sysprocesses.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply