I use extended events to store database errors, like this:
CREATE EVENT SESSION [ErrorCapture] ON SERVER ADD EVENT sqlserver.error_reported ( ACTION ( sqlserver.client_hostname, sqlserver.database_id, sqlserver.sql_text, sqlserver.username ) WHERE ( [severity] >= (11) ) ) ADD TARGET package0.asynchronous_file_target ( SET filename='J:\ServerXmlOutput\ErrorCapture.xel' ) WITH ( MAX_MEMORY=4096 KB, EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS, MAX_DISPATCH_LATENCY=10 SECONDS, MAX_EVENT_SIZE=0 KB, MEMORY_PARTITION_MODE=NONE, TRACK_CAUSALITY=OFF, STARTUP_STATE=ON );
This helps me to easily trace which application is causing them. I have something similar to track slow queries and other special cases. However, I noticed from the SQL Server Profiles that a PHP/Laravel application is not sending some statements directly, but using RPC:Completed: they look like prepared statements, receiving the argument at run time. How do I expand my ErrorCapture to include errors caused by statements executed via RPC:Completed?