Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Grant Exec permissions to all SQL Stored Procs

I've always done some poor man's hack in TextPad to grant EXEC permissions to all stored procedures in a SQL database after restoring from a remote backup or some similar situation.  You know, get a list of stored procs then do a regular expression search and replace until I had my Grant Exec script.

grant exec on DNW_GetRecentPosts to me
grant exec on DNW_HomePageData to me
grant exec on DNW_Stats to me
grant exec on DNW_Total_Stats to me
....


So I decided not to do that anymore and came up with this script which seems to work like a charm (until someone tells me how lame it is and how it can be improved on...)  Until that happens, here's the script to generate a list of Grant exec statements for all stored procs in a database.

declare proccursor CURSOR
GLOBAL
For
Select name
From sysobjects
Where type = 'P' And Status >0
Order By name
open proccursor

fetch next from proccursor into @procname

while @@fetch_status=0
begin
print 'grant exec on ' + @procname + ' to me'
fetch next from proccursor into @procname
end
close proccursor
deallocate proccursor

 

Comments (4) | Post RSS RSS comment feed

Posted on 11/29/2004 2:35:00 PM by Dave Burke
Categories: .NET
Tags:

Related posts

Comments (4) -

11/29/2004 5:25:00 PM Permalink

There's no need to open and iterate a cursor:

Select 'grant exec on ' + [name] + ' to me'
From sysobjects
Where type = 'P' And Status >0
Order By [name]


HTH,

- Aaron

Aaron Robinson |

11/29/2004 6:36:00 PM Permalink

Aaron,  Thanks!  I KNEW there had to be a better way.  I just didn't expect to learn it so quickly!  Thanks for stopping by and for the sweet SQL.

Dave Burke |

11/30/2004 11:13:00 PM Permalink

beautiful...  I just needed that code  for the first time in about a year and this time I knew where to find it, for a change.

Thanks guys.

Shannon J Hager |

12/1/2004 5:29:00 AM Permalink

I'm very happy to be part of a thread that helps my buddy, Swingin' Shannon Hager, the [.net] rocker!  Thanks for visiting, Shannon.

Dave Burke |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke