There are several ways that you can audit who has logged in to your SQL Server. The easiest way is to turn on logon Auditing under server properties. Here you can audit failed logins, successful logins, or both.

This will put the audit records into the Windows event log. The failed logins is pretty useful because there shouldn't be many of them. But the successful logins turns out not to be so helpful because it records every single login which includes the service account. It turns out this logs into the server every few seconds so you end up with so much data in the event log that it's impossible to find anything else, especially the rogue user.

The Enterprise version has a built in auditing option which writes to a user defined event log but again this still suffers the same problem in that it audits every login.

What would be better is a way of selectively auditing only those logins we want to see (or not recording those we aren't interested in).

One way this can be achieve is by using a login trigger to write the login information to a table. We can easily collect the login information we want:

App_Name() will tell us the calling application

HOST_NAME() will tell us the calling computer

eventdata() can return the login name

The trigger can capture the login data and run a query to filter out the logins we don't want to record and then write the data to a table.

In this case I chose to filter on the application name rather than a login name. My thinking here was that a user who can use the application might be tempted to try and use Excel or Access to view the raw data. This worked well but I found the table was filling up with records of me using SSMS. I didn't want to audit the DBA team doing their day to day job but I definitely wanted to audit anyone else using SSMS. So I added a second filter to look for a combination of User Name, Application Name and connecting Host Name.

I've run this on several 2008 servers without any noticeable degradation in performance.

But there is a major drawback of using a Login trigger.

If the code causes an error then the trigger will fail. If it fails then the users can't login. They will receive an error Logon failed for login 'Domain\username' due to trigger execution.

No amount of try- catch, error trapping or transaction rollbacks will help. Any error will cause the trigger to exit as failed I found this out when a new application started using the server but it wasn't added to the LoginsNotToAudit table, the database ran out of room so the insert failed and so the trigger failed and no one could login I now have a daily job that counts the records in the table to check it's not filling up too quickly

If the trigger is failing then the only way to login is to use the Dedicated Administrator Connection or DAC. The Login Trigger doesn't fire when you login using the DAC.

Only sysadmins can use DAC

There can be only one DAC connection at a time

To use DAC with SSMS, prefix the server name with ADMIN: The important point with SSMS is you can only open a query window with DAC you can't use Object Explorer since this uses more than one connection -you will get an error.

By default you can't connect remotely using the DAC so make sure you can RDP to the SQL Server

To allows remote connections use sp_configure, but there is are security implications of allowing remote DAC connections

sp_configure'remote admin connections', 1

reconfigurewithoverride

Once you have your DAC connections you can disable the query using

disabletrigger AuditSQlLogins ONALLSERVER

If you do need to audit logins to SQL this does work very well but does require some administration. Make sure all the DBAs know how to disable the trigger in the event it does fail and keep an eye on the number of records you are collecting. In my experience once you filtered out he DBAs and the application connections there aren't that many records. Which makes looking for the rogue user a bit easier.