Home
%3CLINGO-SUB%20id%3D%22lingo-sub-794833%22%20slang%3D%22en-US%22%3EAZURE%20SQL%20DB%20AND%20LOG%20ANALYTICS%20BETTER%20TOGETHER%20%E2%80%93%20PART%20%231%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-794833%22%20slang%3D%22en-US%22%3E%3CP%3EAs%20a%20DBA%20you%20may%20want%20to%26nbsp%3B%3CSTRONG%3Equery%20SQL%20Audit%3C%2FSTRONG%3E%26nbsp%3Band%26nbsp%3B%3CSTRONG%3ESQL%20Diagnostics%3C%2FSTRONG%3E%26nbsp%3Binformation.%20The%20easiest%20way%20to%20do%20this%20is%20sending%20to%26nbsp%3B%3CSTRONG%3ELog%20analytics%3C%2FSTRONG%3E%26nbsp%3Bthat%20is%20part%20of%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-monitor%2Foverview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Monitor%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EYou%20can%20also%20send%20this%20data%20to%20Event%20Hubs%20and%20storage%20accounts.%20On%20this%20post%20I%20will%20focus%20on%26nbsp%3B%3CSTRONG%3ELog%20Analytics%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126160i6F763C7295D574F9%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_11.png%22%20title%3D%22clipboard_image_11.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1796165542%22%20id%3D%22toc-hId-1796165545%22%3E1%20%E2%80%93%20FIRST%20CREATE%20AN%20LOG%20ANALYTICS%20WORKSPACE%3C%2FH2%3E%0A%3CP%3EClick%20on%26nbsp%3B%3CSTRONG%3ECreate%20a%20Resource%3C%2FSTRONG%3E%26nbsp%3Band%20search%20for%26nbsp%3B%3CSTRONG%3ELog%20Analytics%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126158iFE471C936F5D5F14%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_12.png%22%20title%3D%22clipboard_image_12.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126159i1296357A17FC81BB%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_13.png%22%20title%3D%22clipboard_image_13.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--755991419%22%20id%3D%22toc-hId--755991416%22%3E2%20%E2%80%93%20ENABLE%20AUDIT%20TO%20LOG%20ANALYTICS%3C%2FH2%3E%0A%3CP%3EAt%26nbsp%3B%3CSTRONG%3EServer%20level%3C%2FSTRONG%3E%26nbsp%3Bor%20at%26nbsp%3B%3CSTRONG%3EDatabase%20level%3C%2FSTRONG%3E%2C%20enable%26nbsp%3B%3CSTRONG%3Eauditing%3C%2FSTRONG%3E%26nbsp%3Band%20send%20log%20to%26nbsp%3B%3CSTRONG%3ELog%20Analytics%3C%2FSTRONG%3E%26nbsp%3Band%20select%20the%26nbsp%3B%3CSTRONG%3Eworkspace%3C%2FSTRONG%3E%26nbsp%3Byou%20just%20created%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126161iE79E68B8650945BB%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_14.png%22%20title%3D%22clipboard_image_14.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-986818916%22%20id%3D%22toc-hId-986818919%22%3E3%20%E2%80%93%20ENABLE%20DIAGNOSTICS%20TO%20LOG%20ANALYTICS%3C%2FH2%3E%0A%3CP%3E%3CSTRONG%3E%3CEM%3E*This%20configuration%20is%20done%20PER%20DATABASE%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EClick%20on%26nbsp%3B%3CSTRONG%3EDiagnostics%20Settings%3C%2FSTRONG%3E%26nbsp%3Band%20then%26nbsp%3B%3CSTRONG%3ETurn%20On%20Diagnostics%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126162iC68C5EDE1718F730%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_15.png%22%20title%3D%22clipboard_image_15.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3ESelect%20to%26nbsp%3B%3CSTRONG%3ESend%20to%20Log%20Analytics%3C%2FSTRONG%3E%26nbsp%3Band%20select%20the%26nbsp%3B%3CSTRONG%3ELog%20Analytics%20workspace%3C%2FSTRONG%3E.%20For%20this%20sample%20I%20will%20selected%20only%26nbsp%3B%3CSTRONG%3EErrors%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126163i2D89C183F29E367F%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_16.png%22%20title%3D%22clipboard_image_16.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1565338045%22%20id%3D%22toc-hId--1565338042%22%3E4%20%E2%80%93%20QUERING%20LOG%20ANALYTICS%3C%2FH2%3E%0A%3CP%3EJust%20go%20to%20the%26nbsp%3B%3CSTRONG%3ELog%20Analytics%20workspace%3C%2FSTRONG%3E%26nbsp%3Band%20query%20the%20database%20using%20a%20language%20called%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fkusto%2Fquery%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EKusto%3C%2FA%3E.%20More%20information%20and%20sample%20on%20sintax%20can%20be%20found%20on%20this%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fkusto%2Fquery%2Fsamples%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Elink%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3EA%20Kusto%20query%20is%20a%20read-only%20request%20to%20process%20data%20and%20return%20results.%20The%20request%20is%20stated%20in%20plain%20text%2C%20using%20a%20data-flow%20model%20designed%20to%20make%20the%20syntax%20easy%20to%20read%2C%20author%2C%20and%20automate.%20The%20query%20uses%20schema%20entities%20that%20are%20organized%20in%20a%20hierarchy%20similar%20to%20SQL%E2%80%99s%3A%20databases%2C%20tables%2C%20and%20columns.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EThe%20data%20we%20will%20work%20in%20this%20sample%20can%20be%20found%20on%20table%26nbsp%3B%3CSTRONG%3EAzureDiagnostics%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EJust%20write%20a%20query%20and%20click%26nbsp%3B%3CSTRONG%3ERun%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126164i713B05868F0015C1%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22clipboard_image_17.png%22%20title%3D%22clipboard_image_17.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--19041215%22%20id%3D%22toc-hId--19041212%22%3E4.1%20FAILED%20LOGINS%20SAMPLE%3C%2FH3%3E%0A%3CP%3EFor%20this%20sample%20use%20query%20below%20to%20find%26nbsp%3B%3CSTRONG%3Efailed%20logins%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%2F%2FFailed%20Logins%0AAzureDiagnostics%0A%7C%20where%20TimeGenerated%20%26gt%3B%3D%20ago(5d)%20%2F%2FEvents%20on%20last%205%20days%0A%7C%20where%20action_name_s%20%3D%3D%20%22DATABASE%20AUTHENTICATION%20FAILED%22%0A%7C%20extend%20additional_information_xml%3Dparse_xml(additional_information_s)%0A%7C%20extend%20Error_Code%3Dadditional_information_xml.login_information.error_code%0A%7C%20extend%20Error_State%3Dadditional_information_xml.login_information.error_state%0A%7C%20project%0A%20%20%20%20TimeGenerated%2C%20event_time_t%2C%0A%20%20%20%20ResourceGroup%2C%20LogicalServerName_s%2C%20database_name_s%2C%0A%20%20%20%20session_id_d%2C%20client_ip_s%2C%20application_name_s%2C%20session_server_principal_name_s%2C%0A%20%20%20%20Error_Code%2C%20Error_State%0A%7C%20order%20by%20TimeGenerated%20desc%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EExpanding%20this%20event%20we%20can%20see%20all%20information%20from%20this%20event%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EDate%2FTime%3C%2FLI%3E%0A%3CLI%3EServer%3C%2FLI%3E%0A%3CLI%3EDB%3C%2FLI%3E%0A%3CLI%3EApplication%20Name%3C%2FLI%3E%0A%3CLI%3EUser%3C%2FLI%3E%0A%3CLI%3EIP%3C%2FLI%3E%0A%3CLI%3EError%20Code%20and%20Error%20State%3C%2FLI%3E%0A%3CLI%3Eetc%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126166iB96DB0C92002A0E9%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22clipboard_image_18.png%22%20title%3D%22clipboard_image_18.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EYou%20can%20then%20use%20this%26nbsp%3B%3CSTRONG%3EError%20Code%3C%2FSTRONG%3E%26nbsp%3Band%26nbsp%3B%3CSTRONG%3EState%3C%2FSTRONG%3E%26nbsp%3Bto%20find%20what%20is%20the%20error%20description%3C%2FP%3E%0A%3CP%3EIn%20this%20case%3A%3C%2FP%3E%0A%3CP%3E%E2%80%93%20Error%2018456%3A%20Login%20failed%20for%20user%20%E2%80%98%25.%3CEM%3Els%E2%80%99.%25.%3C%2FEM%3Els%26nbsp%3B%3CBR%20%2F%3E%E2%80%93%20State%208%3A%20The%20password%20is%20incorrect%3C%2FP%3E%0A%3CP%3EREF%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Ferrors-events%2Fmssqlserver-18456-database-engine-error%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Ferrors-events%2Fmssqlserver-18456-database-engine-error%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1723769120%22%20id%3D%22toc-hId-1723769123%22%3E4.2%20ERRORS%20GENERIC%3C%2FH3%3E%0A%3CP%3EUse%20the%20query%20below%20to%20find%20all%20errors%20or%20specific%20errors%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%2F%2FErrors%20Query%0AAzureDiagnostics%0A%7C%20where%20TimeGenerated%20%26gt%3B%3D%20ago(30d)%20%2F%2F%20Last%2030%20days%0A%7C%20where%20Category%20%3D~%20%22Errors%22%0A%7C%20where%20error_number_d%20%3D%3D%208134%20%2F%2FDivide%20by%20zero%20error%20encountered.%0A%2F%2F%7C%20where%20Message%20contains%20%22divide%22%20%2F%2FOr%20search%20by%20text%0A%7C%20project%0A%20%20%20%20TimeGenerated%2C%0A%20%20%20%20ResourceGroup%2C%0A%20%20%20%20LogicalServerName_s%2C%0A%20%20%20%20DatabaseName_s%2C%0A%20%20%20%20Message%2C%0A%20%20%20%20error_number_d%2C%0A%20%20%20%20Severity%2C%0A%20%20%20%20state_d%0A%7C%20order%20by%20TimeGenerated%20desc%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20find%20some%20information%20related%20to%20the%20errors.%20Can%20be%20useful%20to%20consolidate%20information%2C%20histogram%2C%20alerts%2C%20etc%3C%2FP%3E%0A%3CP%3E*Notice%20that%20there%20is%20no%20information%20on%20who%20caused%20the%20error.%20Because%20this%20information%20came%20from%20Diagnostics%20information%2C%20not%20the%20audit%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126165i0DBDF7A46C992D72%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22clipboard_image_19.png%22%20title%3D%22clipboard_image_19.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3E4.3%20ERRORS%20DETAILED%3C%2FP%3E%0A%3CP%3EWith%20this%20other%20sample%20below%20you%20can%20get%20the%20queries%20that%20failed%20with%20full%20information%20on%20who%20did%20it%2C%20what%20query%2C%20etc.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%2F%2FDetailed%20errors%0AAzureDiagnostics%0A%7C%20where%20TimeGenerated%20%26gt%3B%3D%20ago(15d)%20%20%2F%2FLast%2015%20days%0A%7C%20where%20Category%20%3D~%20%22SQLSecurityAuditEvents%22%0A%7C%20where%20succeeded_s%20%3D%3D%20%22false%22%0A%7C%20where%20additional_information_s%20contains%20%228134%22%20%2F%2FLooking%20for%20specift%20error.%20Ex%20Div%20by%20zero%0A%7C%20extend%20additional_information_xml%3Dparse_xml(additional_information_s)%0A%7C%20extend%20failure_reason%3Dadditional_information_xml.batch_information.failure_reason%0A%7C%20project%20%20%20%20%0A%20%20%20%20ResourceGroup%2C%0A%20%20%20%20LogicalServerName_s%2C%0A%20%20%20%20database_name_s%2C%0A%20%20%20%20session_id_d%2C%0A%20%20%20%20action_name_s%2C%0A%20%20%20%20client_ip_s%2C%0A%20%20%20%20application_name_s%2C%0A%20%20%20%20failure_reason%2C%0A%20%20%20%20statement_s%2C%0A%20%20%20%20additional_information_s%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126167iD498B5FD46AF1E94%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22clipboard_image_20.png%22%20title%3D%22clipboard_image_20.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--631874336%22%20id%3D%22toc-hId--631874333%22%3E5%20%E2%80%93%20YOU%20CAN%20ALSO%20MONITOR%20USING%20AZURE%20SQL%20ANALYTICS%20(PREVIEW)%3C%2FH2%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-monitor%2Finsights%2Fazure-sql%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-monitor%2Finsights%2Fazure-sql%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EI%20will%20not%20speak%20about%20it%20on%20this%20article%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F126168i2E835A8E7FCDD059%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_21.png%22%20title%3D%22clipboard_image_21.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EThere%20will%20be%20more%20articles%20on%20this%20topic%20Azure%20SQL%20DB%20%2B%20Log%20Analytics%3C%2FP%3E%0A%3CP%3EMore%20information%20can%20be%20found%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-database%2Fsql-database-metrics-diag-logging%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-database%2Fsql-database-metrics-diag-logging%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-database%2Fsql-database-auditing%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-database%2Fsql-database-auditing%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-monitor%2Fplatform%2Fmanage-access%23create-a-workspace%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-monitor%2Fplatform%2Fmanage-access%23create-a-workspace%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ERepublishing%20original%20post%20published%20at%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ffonsecasergio.wordpress.com%2F2019%2F03%2F30%2Fazure-sql-db-and-log-analytics-part-1%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Ffonsecasergio.wordpress.com%2F2019%2F03%2F30%2Fazure-sql-db-and-log-analytics-part-1%2F%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-794833%22%20slang%3D%22en-US%22%3E%3CP%3EAs%20a%20DBA%20you%20may%20want%20to%26nbsp%3B%3CSTRONG%3Equery%20SQL%20Audit%3C%2FSTRONG%3E%26nbsp%3Band%26nbsp%3B%3CSTRONG%3ESQL%20Diagnostics%3C%2FSTRONG%3E%26nbsp%3Binformation.%20The%20easiest%20way%20to%20do%20this%20is%20sending%20to%26nbsp%3B%3CSTRONG%3ELog%20analytics%3C%2FSTRONG%3E%26nbsp%3Bthat%20is%20part%20of%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-monitor%2Foverview%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EAzure%20Monitor%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EYou%20can%20also%20send%20this%20data%20to%20Event%20Hubs%20and%20storage%20accounts.%20On%20this%20post%20I%20will%20focus%20on%26nbsp%3B%3CSTRONG%3ELog%20Analytics%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-794833%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20SQL%20DB%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

As a DBA you may want to query SQL Audit and SQL Diagnostics information. The easiest way to do this is sending to Log analytics that is part of Azure Monitor

You can also send this data to Event Hubs and storage accounts. On this post I will focus on Log Analytics

clipboard_image_11.png

1 – FIRST CREATE AN LOG ANALYTICS WORKSPACE

Click on Create a Resource and search for Log Analytics

clipboard_image_12.png

clipboard_image_13.png

 

2 – ENABLE AUDIT TO LOG ANALYTICS

At Server level or at Database level, enable auditing and send log to Log Analytics and select the workspace you just created

clipboard_image_14.png

 

3 – ENABLE DIAGNOSTICS TO LOG ANALYTICS

*This configuration is done PER DATABASE

Click on Diagnostics Settings and then Turn On Diagnostics

clipboard_image_15.png



Select to Send to Log Analytics and select the Log Analytics workspace. For this sample I will selected only Errors

clipboard_image_16.png



4 – QUERING LOG ANALYTICS

Just go to the Log Analytics workspace and query the database using a language called Kusto. More information and sample on sintax can be found on this link

A Kusto query is a read-only request to process data and return results. The request is stated in plain text, using a data-flow model designed to make the syntax easy to read, author, and automate. The query uses schema entities that are organized in a hierarchy similar to SQL’s: databases, tables, and columns.

The data we will work in this sample can be found on table AzureDiagnostics

Just write a query and click Run

clipboard_image_17.png

 

4.1 FAILED LOGINS SAMPLE

For this sample use query below to find failed logins

 

 

//Failed Logins
AzureDiagnostics
| where TimeGenerated >= ago(5d) //Events on last 5 days
| where action_name_s == "DATABASE AUTHENTICATION FAILED"
| extend additional_information_xml=parse_xml(additional_information_s)
| extend Error_Code=additional_information_xml.login_information.error_code
| extend Error_State=additional_information_xml.login_information.error_state
| project
    TimeGenerated, event_time_t,
    ResourceGroup, LogicalServerName_s, database_name_s,
    session_id_d, client_ip_s, application_name_s, session_server_principal_name_s,
    Error_Code, Error_State
| order by TimeGenerated desc

 

 

 

Expanding this event we can see all information from this event

  • Date/Time
  • Server
  • DB
  • Application Name
  • User
  • IP
  • Error Code and Error State
  • etc

clipboard_image_18.png

You can then use this Error Code and State to find what is the error description

In this case:

– Error 18456: Login failed for user ‘%.ls’.%.ls 
– State 8: The password is incorrect

REF: https://docs.microsoft.com/en-us/sql/relational-databases/errors-events/mssqlserver-18456-database-e...

 

4.2 ERRORS GENERIC

Use the query below to find all errors or specific errors

 

 

//Errors Query
AzureDiagnostics
| where TimeGenerated >= ago(30d) // Last 30 days
| where Category =~ "Errors"
| where error_number_d == 8134 //Divide by zero error encountered.
//| where Message contains "divide" //Or search by text
| project
    TimeGenerated,
    ResourceGroup,
    LogicalServerName_s,
    DatabaseName_s,
    Message,
    error_number_d,
    Severity,
    state_d
| order by TimeGenerated desc

 

 

 

 

You can find some information related to the errors. Can be useful to consolidate information, histogram, alerts, etc

*Notice that there is no information on who caused the error. Because this information came from Diagnostics information, not the audit

clipboard_image_19.png



4.3 ERRORS DETAILED

With this other sample below you can get the queries that failed with full information on who did it, what query, etc.

 

 

 

//Detailed errors
AzureDiagnostics
| where TimeGenerated >= ago(15d)  //Last 15 days
| where Category =~ "SQLSecurityAuditEvents"
| where succeeded_s == "false"
| where additional_information_s contains "8134" //Looking for specift error. Ex Div by zero
| extend additional_information_xml=parse_xml(additional_information_s)
| extend failure_reason=additional_information_xml.batch_information.failure_reason
| project    
    ResourceGroup,
    LogicalServerName_s,
    database_name_s,
    session_id_d,
    action_name_s,
    client_ip_s,
    application_name_s,
    failure_reason,
    statement_s,
    additional_information_s

 

 

 

clipboard_image_20.png

 

5 – YOU CAN ALSO MONITOR USING AZURE SQL ANALYTICS (PREVIEW)

https://docs.microsoft.com/en-us/azure/azure-monitor/insights/azure-sql

I will not speak about it on this article

clipboard_image_21.png

There will be more articles on this topic Azure SQL DB + Log Analytics

More information can be found

 

Republishing original post published at https://fonsecasergio.wordpress.com/2019/03/30/azure-sql-db-and-log-analytics-part-1/