August 18, 2013 at 4:24 pm
Is there any way I can enable/disable a sql/nt account by running a stored poc?
August 19, 2013 at 12:17 am
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
August 20, 2013 at 11:36 am
It works.... Thanks
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply