Logon trigger is basically used for auditing, and controlling logins or sessions on SQL Server.
But it could be used for several purposes like :
- Deny access for particular client application(eg. Clients connecting from ODBC , OLEdb etc.)
- Allow login for certain time period in a day.
Tracking login activity
And many more.
Creating a LOGON trigger
Here in following code snippet I have created a simple Logon trigger for : If someone is connecting with SQL Server from any other client application a part form SSMS(SQL Server Management Studio.)
Will get an Error: “Logon failed for sa due to trigger execution.”
CREATE TRIGGER [DenyAccess]
ON ALL SERVER WITH EXECUTE AS 'sa'
FOR LOGON
AS
BEGIN
DECLARE @data XML
SET @data = EVENTDATA()
DECLARE @AppName sysname

Anupam SinghPosted May 27, 2014, 1:44 AM
hi Sagar we can drop it using DROP TRIGGER [trg_name] ON ALL SERVER and can disable using DISABLE TRIGGER [trg_name ] ON ALL SERVER.
Leon PuthPosted May 21, 2014, 8:15 AM
be very careful if you implement this and get it wrong you may lock yourself out of sql altogether.