Is it possible to change the login auditing settings of a SQL Server database by script, rather than through the Server Properties Security setting in the SSMS UI?
I need to programatically change the setting to "None", and then back to "Failed logins only"
Best Answer
Sure, here are the commands listed below. (Reformatted from original post for reading ease.)
These can derived from clicking on
Server Properties
, then choosing theSecurity
tab and changing theLogin auditing
settings and scripting out the code, instead of clicking on theOK
button to close the dialog. This type of scripting is usually an option on actions taken through the SSMS interface.So, for your requirement just set the key to 0 (no auditing) then back to 2 (failed only).
But, alas, as Shawn Melton pointed out, it requires the server to be restarted before the change can be applied. Of course, you can program for restarting the server as well. Does allowing a restart (or 2 restarts) fit into your process?