Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Disable/Enable Account Expand / Collapse
Author
Message
Posted Sunday, August 18, 2013 4:24 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, August 8, 2014 7:26 AM
Points: 18, Visits: 252
Is there any way I can enable/disable a sql/nt account by running a stored poc?
Post #1485622
Posted Monday, August 19, 2013 12:17 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 4:44 AM
Points: 2,397, Visits: 2,935
Yes, it's possible. You have to use dynamic SQL to accomplish it. Below I quickly created a small stored procedure that does the trick. I didn't include any error handling, so alter it to your needs before taking it in production.
create procedure toggle_login (@login_name nvarchar(125), @set_enable bit)
as
begin
declare @sql_command nvarchar(500)
set @sql_command = 'ALTER LOGIN [' + @login_name + '] ' + case when @set_enable = 1 then 'ENABLE' else 'DISABLE' end
print @sql_command
exec sp_executesql @sql_command
end


-- usage of above stored procedure
exec toggle_login 'test', true



** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
Post #1485657
Posted Tuesday, August 20, 2013 11:36 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, August 8, 2014 7:26 AM
Points: 18, Visits: 252
It works.... Thanks
Post #1486381
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse