As many of you know, a data breach is a big deal. Not only do they place your customers at risk, a data breach can also have a very negative impact on the reputation of the company you work for. As a DBA, I teach my students that we are the last line of defense against a breach. I feel that an important part of protecting the data is to investigate failed logins. However, in order to investigate them, we need to find the failed logins first.You may be asking, if investigating failed logins is important, how do I find them? There are a few methods we can use, including reading the log, SQL Server Audit and using Extended Events. We will cover each of these including how to set it up and read the data in the next several blog posts.
Extended Events
Of all the options listed above, the first two are viable options, however they will not work on an Azure SQL DB. The third option above is the first that will also work in an Azure SQL DB. This third option is Extended Events. Unlike SQL Server Audit, there is NOT a failed login event. We will need to use the Error_Reported event instead.
When looking at the image of the error log below, you can see the error number, severity and state of a failed login. These numbers will be critical when setting up the Failed Login Extended Event session.

This is the code needed to create the Extended Event session. Although, there are several targets that can be used for storage, I think that the file is the best target to use. You will need to change the path to one that is suitable for your environment. Notice the WHERE clause, the Error, severity and state all match the above image.
- CREATE EVENT SESSION [FailedLogins] ON SERVER
- ADD EVENT sqlserver.error_reported(
- ACTION(sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.nt_username)
- WHERE ([severity]=(14) AND [error_number]=(18456) AND [state]>(1)))
- ADD TARGET package0.event_file(SET filename=N'C:\temp\FailedLogins.xel')
- GO
Like the audits, the Extended Event session will need to be enabled before it can collect the desired data. To start a session, simply right click on the session and go to "Start Session". By looking at the session in SSMS, you can easily tell if the session is enabled or not.

Once the session is started, SQL Server will create a .xel file in the destination location. Once you go to the location, you will notice something a bit unusual about the file names. Look at the huge number at the end. I have looked and looked and the only thing I can find is that this number is the number of seconds since some date in the 1600's, but not sure if that is totally true or not.

Because this is an XML based document, it would be logical to think to read the data we could simply open the document in Notepad as you will see below. Well, that is not the case. If you try to open one of these files with Notepad, it will look something like this. Not exactly useful.



Join the conversation! Your thoughts help the community grow.