How can I get all the failure SQL queries logs o

Robert Antwi 0 Reputation points
2025-01-29T13:45:01.7433333+00:00

I want to track all the failure SQL in the log metrics, how can i get the output

Azure SQL Database
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,398 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Shikha Ghildiyal 3,340 Reputation points Microsoft Employee
    2025-01-29T15:19:44.4633333+00:00

    HI,

    Thanks for reaching out to Microsoft Q&A.

    You can enable the audit logs for this purpose.

    Please find detailed guidance in below link :

    https://learn.microsoft.com/en-us/azure/azure-sql/managed-instance/auditing-configure?view=azuresql

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

  2. Alberto Morillo 34,451 Reputation points MVP
    2025-01-29T16:44:30.7566667+00:00

    You can use Extended Events to capture all T-SQL instructions failing. Use the sqlserver.error_reported event as shown below:

    CREATE EVENT SESSION azure_monitor
    ON DATABASE
    
    ADD EVENT sqlserver.error_reported(
    ACTION (sqlserver.client_app_name, sqlserver.client_hostname, sqlserver.session_id, sqlserver.sql_text,
            sqlserver.username))
    
    
    

    You can capture failures and store then on a file located on an Azure Storage Account container.

    0 comments No comments

  3. Javier Villegas 900 Reputation points MVP
    2025-01-29T19:11:42.87+00:00

    Hi @Robert Antwi

    Here is an example of an Extedned Events Session to collect SQL Errors. this is actually the one I use

    If you don't feel confortable with Extended Events you can try using SQL Profiler and capture error_reported events (but I do not recommend this option)

    CREATE EVENT SESSION [sql_text_and_errors] ON SERVER 
    ADD EVENT sqlserver.error_reported(
        ACTION(sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.database_id,sqlserver.sql_text,sqlserver.tsql_stack,sqlserver.username)
        WHERE ([error_number]<>(2528) AND [error_number]<>(3014) AND [error_number]<>(4035) AND [error_number]<>(8153) AND [error_number]<>(5701) AND [error_number]<>(5703) AND [error_number]<>(8153) 
    	AND [error_number]<>(22803) AND [error_number]<>(18265) AND [error_number]<>(14205) AND [error_number]<>(14213) AND [error_number]<>(14214) AND [error_number]<>(14215) AND [error_number]<>(14216) 
    	AND [error_number]<>(14549) AND [error_number]<>(14558) AND [error_number]<>(14559) AND [error_number]<>(14560) AND [error_number]<>(14561) AND [error_number]<>(14562) AND [error_number]<>(14563) 
    	AND [error_number]<>(14564) AND [error_number]<>(14565) AND [error_number]<>(14566) AND [error_number]<>(14567) AND [error_number]<>(14568) AND [error_number]<>(14569) AND [error_number]<>(14570) 
    	AND [error_number]<>(14635) AND [error_number]<>(14638) AND [error_number]<>(951) AND [error_number]<>(3211) AND [error_number]<>(9104) AND [error_number]<=(50000))) 
    ADD TARGET package0.event_file(SET filename=N'C:\Temp\xEvent_Errors',max_file_size=(4000))
    WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=1 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=ON,STARTUP_STATE=ON)
    GO
    ALTER EVENT SESSION sql_text_and_errors ON SERVER
    STATE=START;
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.