5
(1)

Being a part of database team, you will have some sort of monitoring system through which you would be receiving SQL Server alerts and these alerts are collected from SQL Server Error log and Event Viewer log. There are occasions wherein you are working on any monitoring setup and as part of that work, you want to generate some test alerts in event viewer log to see if monitoring tool is picking up that alert or not. In this article, we will see how to write events in the Windows Event Viewer log.

How to View Event Viewer Log:

search for word "event" from your windows search bar and you would see as below.

Method#1:

Method#2:

go to start button — >type eventvwr in search bar as shown below.

Windows event viewer log will get opened. now go to Windows Logs –> Application(as shown below). on right hand side of Application, you can see all the SQL Server related events along with some other Windows level events.

How to write events in Event Viewer Log:

Power Shell Syntax:

"Write-EventLog -LogName $LogName -Source $Source -EntryType $EntryType -EventId $EventID -Message $Message"

Power Shell Example:

Write-Eventlog -LogName Application -Source "MSSQLSERVER" -EntryType Error -EventID 24026 -Message "Monitoring Testing"

where,

Write-Eventlog –> this will write specified event to event viewer log.

LogName Application –> event will be written to application log as shown in above snap.

Source "MSSQLSERVER" –> since our events are related to SQL Server, so we will keep source as "MSSQLSERVER"

EntryType Error –> we will keep EntryType as Error

EventID 24026 –> mention the event id that you want to insert in event log.

Before inserting event in event log:

After inserting event in event log:

How to filter event id from event viewer:

First click on Filter Current Log from the Actions pane available on right hand side of event viewer log.

Mention event id that you want to filter from the log. Also, you can choose event level as per your requirement.

List of All event viewer ID's:

Event ID Description
24000Audit event in SQL server
24001Login succeeded in SQL server
24002Logout succeeded in SQL server
24003Login failed in SQL server
24004Change own password succeeded in SQL server
24005Change own password failed in SQL server
24006Change password succeeded in SQL server
24007Change password failed in SQL server
24008Reset own password succeeded in SQL server
24009Reset own password failed in SQL server
24010Reset password succeeded in SQL server
24011Reset password failed in SQL server
24012User must change password in SQL server
24013User account unlocked in SQL server
24014Application role password successfully changed in SQL server
24015Application role password change failed in SQL server
24016Add member to SQL server role succeeded
24017Add member to SQL server role failed
24018Remove member from SQL server role succeeded
24019Remove member from SQL server role failed
24020Add member to database role in SQL server succeeded
24021Add member to database role in SQL server failed
24022Remove member from database role in SQL server succeeded
24023Remove member from database role in SQL server failed
24024Database backup command issued in SQL server
24025Transaction log backup command issued in SQL server
24026Database restore command issued in SQL server
24027Transaction log restore command issued in SQL server
24028Database console command issued in SQL server
24029Bulk administration command issued in SQL server
24030Alter connection command issued in SQL server
24031Alter resources command issued in SQL server
24032Alter server state command issued in SQL server
24033Alter server settings command issuedin SQL server
24034View server state command issued in SQL server
24035External access assembly command issued in SQL server
24036Unsafe assembly command issued in SQL server
24037Alter resource governor command issued in SQL server
24038Database authenticate command issued in SQL server
24039Database checkpoint command issued in SQL server
24040Database show plan command issued in SQL server
24041Subscribe to query information command issued in SQL server
24042View database state command issued in SQL server
24043Change server audit command issued in SQL server
24044Change server audit specification command issued in SQL server
24045Change database audit specification command issued in SQL server
24046Create server audit command issued in SQL server
24047Create server audit specification command issued in SQL server
24048Create database audit specification command issued in SQL server
24049Delete server audit command issued in SQL server
24050Delete server audit specification command issued in SQL server
24051Delete database audit specification command issued in SQL server
24052Audit failure in SQL server
24053Audit session changed in SQL server
24054SQL server started
24055SQL server paused
24056SQL server resumed
24057SQL server stopped
24058Create server object command issued in SQL server
24059Change server object command issued in SQL server
24060Delete server object command issued in SQL server
24061Create server setting command issued in SQL server
24062Change server setting command issued in SQL server
24063Delete server setting command issued in SQL server
24064Create server cryptographic provider command issued in SQL server
24065Delete server cryptographic provider command issued in SQL server
24066Change server cryptographic provider command issued in SQL server
24067Create server credential command issued in SQL server
24068Delete server credential command issued in SQL server
24069Change server credential command issued in SQL server
24070Change server master key command issued in SQL server
24071Back up server master key command issued in SQL server
24072Restore server master key command issued in SQL server
24073Map server credential to login command issued in SQL server
24074Remove map between server credential and login command issued in SQL server
24075Create server principal command issued in SQL server
24076Delete server principal command issued in SQL server
24077Change server principal credentials command issued in SQL server
24078Disable server principal command issued in SQL server
24079Change server principal default database command issued in SQL server
24080Enable server principal command issued in SQL server
24081Change server principal default language command issued in SQL server
24082Change server principal password expiration command issued in SQL server
24083Change server principal password policy command issued in SQL server
24084Change server principal name command issued in SQL server
24085Create database command issued in SQL server
24086Change database command issued in SQL server
24087Delete database command issued in SQL server
24088Create certificate command issued in SQL server
24089Change certificate command issued in SQL server
24090Delete certificate command issued in SQL server
24091Back up certificate command issued in SQL server
24092Access certificate command issued in SQL server
24093Create asymmetric key command issued in SQL server
24094Change asymmetric key command issued in SQL server
24095Delete asymmetric key command issued in SQL server
24096Access asymmetric key command issued in SQL server
24097Create database master key command issued in SQL server
24098Change database master key command issued in SQL server
24099Delete database master key command issued in SQL server
24100Back up database master key command issued in SQL server
24101Restore database master key command in SQL server
24102Open database master key command issued in SQL server
24103Create database symmetric key command issued in SQL server
24104Change database symmetric key command issued in SQL server
24105Delete database symmetric key command issued in SQL server
24106Back up database symmetric key command issued in SQL server
24107Open database symmetric key command issued in SQL server
24108Create database object command issued in SQL server
24109Change database object command issued in SQL server
24110Delete database object command issued in SQL server
24111Access database object command issued in SQL server
24112Create assembly command issued in SQL server
24113Change assembly command issued in SQL server
24114Delete assembly command issued in SQL server
24115Create schema command issued in SQL server
24116Change schema command issued in SQL server
24117Delete schema command issued in SQL server
24118Create database encryption key command issued in SQL server
24119Change database encryption key command issued in SQL server
24120Delete database encryption key command issued in SQL server
24121Create database user command issued in SQL server
24122Change database user command issued in SQL server
24123Delete database user command issued in SQL server
24124Create database role command issued in SQL server
24125Change database role command issued in SQL server
24126Delete database role command issued in SQL server
24127Create application role command issued in SQL server
24128Change application role command issued in SQL server
24129Create application role command issued in SQL server
24130Change database user login command issued in SQL server
24131Auto-change database user login command issued in SQL server
24132Create schema object command issued in SQL server
24133Change schema object command issued in SQL server
24134Delete schema object command issued in SQL server
24135Transfer schema object command issued in SQL server
24136Create schema type command issued in SQL server
24137Change schema type command issued in SQL server
24138Delete schema type command issued in SQL server
24139Transfer schema type command issued in SQL server
24140Create XML schema collection command issued in SQL server
24141Change XML schema collection command issued in SQL server
24142Delete XML schema collection command issued in SQL server
24143Transfer XML schema collection command issued in SQL server
24144Impersonate within server scope command issued in SQL server
24145Impersonate within database scope command issued in SQL server
24146Change server object owner command issued in SQL server
24147Change database owner command issued in SQL server
24148Change schema owner command issued in SQL server
24150Change role owner command issued in SQL server
24151Change database object owner command issued in SQL server
24152Change symmetric key owner command issued in SQL server
24153Change certificate owner command issued in SQL server
24154Change asymmetric key owner command issued in SQL server
24155Change schema object owner command issued in SQL server
24156Change schema type owner command issued in SQL server
24157Change XML schema collection owner command issued in SQL server
24158Grant permissions succeeded in SQL server
24159Grant permissions failed in SQL server
24160Grant server permissions with grant succeeded in SQL server
24161Grant server permissions with grant failed in SQL server
24162Deny server permissions succeeded in SQL server
24163Deny server permissions failed in SQL server
24164Deny server permissions with cascade succeeded in SQL server
24165Deny server permissions with cascade failed in SQL server
24166Revoke server permissions succeeded in SQL server
24167Revoke server permissions failed in SQL server
24168Revoke server permissions with grant succeeded in SQL server
24169Revoke server permissions with grant failed in SQL server
24170Revoke server permissions with cascade succeeded in SQL server
24171Revoke server permissions with cascade failed in SQL server
24172Grant server object permissions command issued in SQL server
24173Grant server object permissions with grant command issued in SQL server
24174Deny server object permissions command issued in SQL server
24175Deny server object permissions with cascade command issued in SQL server
24176Revoke server object permissions command issued in SQL server
24177Revoke server object permissions with grant command issued in SQL server
24178Revoke server object permissions with cascade command issued in SQL server
24179Grant database permissions succeeded in SQL server
24180Grant database permissions failed in SQL server
24181Grant database permissions with grant succeeded in SQL server
24182Grant database permissions with grant failed in SQL server
24183Deny database permissions succeeded in SQL server
24184Deny database permissions failed in SQL server
24185Deny database permissions with cascade succeeded in SQL server
24186Deny database permissions with cascade failed in SQL server
24187Revoke database permissions succeeded in SQL server
24188Revoke server permissions failed in SQL server
24189Revoke database permissions with grant succeeded in SQL server
24190Revoke database permissions with grant failed in SQL server
24191Revoke database permissions with cascade succeeded in SQL server
24192Revoke database permissions with cascade failed in SQL server
24193Grant database object permissions command issued in SQL server
24194Grant database object permissions with grant command issued in SQL server
24195Deny server object permissions command issued in SQL server
24196Deny database object permissions with cascade command issued in SQL server
24197Revoke database object permissions command issued in SQL server
24198Revoke database object permissions with grant command issued in SQL server
24199Revoke database object permissions with cascade command issued in SQL server
24200Grant schema permissions command issued in SQL server
24201Grant schema permissions with grant command issued in SQL server
24202Deny schema permissions command issued in SQL server
24203Deny schema permissions with cascade command issued in SQL server
24204Revoke schema permissions command issued in SQL server
24205Revoke schema permissions with grant command issued in SQL server
24206Revoke schema permissions with cascade command issued in SQL server
24207Grant assembly permissions command issued in SQL server
24208Grant assembly permissions with grant command issued in SQL server
24209Deny assembly permissions command issued in SQL server
24210Deny assembly permissions with cascade command issued in SQL server
24211Revoke assembly permissions command issued in SQL server
24212Revoke assembly permissions with grant command issued in SQL server
24213Revoke assembly permissions with cascade command issued in SQL server
24214grant database role permissions command issued in SQL server
24215Grant database role permissions with grant command issued in SQL server
24216Deny database role permissions command issued in SQL server
24217Deny database role permissions with cascade command issued in SQL server
24218Revoke database role permissions command issued in SQL server
24219Revoke database role permissions with grant command issued in SQL server
24220Revoke database role permissions with cascade command issued in SQL server
24221Grant application role permissions command issued in SQL server
24222Grant application role permissions command issued in SQL server
24223Deny application role permissions command issued in SQL server
24224Deny application role permissions with cascade command issued in SQL server
24225Revoke application role permissions command issued in SQL server
24226Revoke application role permissions with grant command issued in SQL server
24227Revoke application role permissions with cascade command issued in SQL server
24228Grant symmetric key permissions command issued in SQL server
24229grant symmetric key permissions with grant command issued in SQL server
24230Deny symmetric key permissions command issued in SQL server
24231Deny symmetric key permissions with cascade command issued in SQL server
24232Revoke application role permissions command issued in SQL server
24233Revoke symmetric key permissions with grant command issued in SQL server
24234Revoke symmetric key permissions with grant command issued in SQL server
24235Grant certificate permissions command issued in SQL server
24236Grant certificate permissions with grant command issued in SQL server
24237Deny certificate permissions command issued in SQL server
24238Deny certificate permissions with cascade command issued in SQL server
24239Revoke certificate permissions command issued in SQL server
24240Revoke certificate permissions with grant command issued in SQL server
24241Revoke certificate permissions with cascade command issued in SQL server
24242Grant asymmetric key permissions command issued in SQL server
24243Grant asymmetric key permissions with grant command issued in SQL server
24244Deny asymmetric key permissions command issued in SQL server
24245Deny asymmetric key permissions with cascade command issued in SQL server
24246Revoke asymmetric key permissions command issued in SQL server
24247Revoke asymmetric key permissions with grant command issued in SQL server
24248Revoke asymmetric key permissions command issued in SQL server
24249Grant schema object permissions command issued in SQL server
24250Grant schema object permissions with grant command issued in SQL server
24251Deny schema object permissions command issued in SQL server
24252Deny schema object permissions with cascade command issued in SQL server
24253Revoke schema object permissions command issued in SQL server
24254Revoke schema object permissions with grant command issued in SQL server
24255Revoke schema object permissions with cascade command issued in SQL server
24256Grant schema type permissions command issued in SQL server
24257Grant schema type permissions with grant command issued in SQL server
24258Deny schema type permissions command issued in SQL server
24259Deny schema type permissions with cascade command issued in SQL server
24260Revoke schema type permissions command issued in SQL server
24261Revoke schema type permissions with grant command issued in SQL server
24262Revoke schema type permissions with cascade command issued in SQL server
24263Grant XML schema collection permissions command issued in SQL server
24264Grant XML schema collection permissions with grant command issued in SQL server
24265Deny XML schema collection permissions command issued in SQL server
24266Deny XML schema collection permissions with cascade command issued in SQL server
24267RevokeÿXML schema collection permissions command issued in SQL server
24268Revoke XML schema collection permissions with grant command issued in SQL server
24269Revoke XML schema collection permissions with cascade command issued in SQL server
24270Reference database object permissions command issued in SQL server
24271Send service request command issued in SQL server
24272Check permissions with schema command issued in SQL server
24273Use service broker transport security command issued in SQL server
24274Use database mirroring transport security command issued in SQL server
24275Alter trace command issued in SQL server
24276Start trace command issued in SQL server
24277Stop trace command issued in SQL server
24278Enable trace C2 audit mode command issued in SQL server
24279Disable trace C2 audit mode command issued in SQL server
24280Server full-text command issued in SQL server
24281Select command issued in SQL server
24282Update command issued in SQL server
24283Insert command issued in SQL server
24284Delete command issued in SQL server
24285Execute command issued in SQL server
24286Receive command issued in SQL server
24287Check references command issued in SQL server
24288Create user-defined server role command issued in SQL server
24289Change user-defined server role command issued in SQL server
24290Delete user-defined server role command issued in SQL server
24291Grant user-defined server role permissions command issued in SQL server
24292Grant user-defined server role permissions with grant command issued in SQL server
24293Deny user-defined server role permissions command issued in SQL server
24294Deny user-defined server role permissions with cascade command issued in SQL server
24295Revoke user-defined server role permissions command issued in SQL server
24296Revoke user-defined server role permissions with grant command issued in SQL server
24297Revoke user-defined server role permissions with cascade command issued in SQL server
24298Database login succeeded in SQL server
24299Database login failed in SQL server
24300Database logout succeeded in SQL server
24301Change database password succeeded in SQL server
24302Change database password failed in SQL server
24303Change own database password succeeded in SQL server
24304Change own database password failed in SQL server
24305Reset own database password succeeded in SQL server
24306Reset own password failed in SQL server
24307Reset database password succeeded in SQL server
24308Reset database password failed in SQL server
24309Copy passwordÿ in SQL server
24310User-defined audit eventÿin SQL server
24311Change database audit command issued in SQL server
24312Create database audit command issued in SQL server
24313Delete database audit command issued in SQL server
24314Begin transaction command issued in SQL server
24315Commit transaction command issued in SQL server
24316Rollback transaction command issued in SQL server
24317Create column master key command issued in SQL server
24318Delete column master key command issued in SQL server
24319Column master key viewed in SQL server
24320Create column encryption key command issued in SQL server
24321Change column encryption key command issued in SQL server
24322Delete column encryption key command issued in SQL server
24323Column encryption key viewed in SQL server
24324Create database credential command issued in SQL server
24325Change database credential command issued in SQL server
24326Delete database credential command issued in SQL server
24327Change database scoped configuration command issued in SQL server
24328Create external data source command issued in SQL server
24329Change external data source command issued in SQL server
24330Delete external data source command issued in SQL server
24331Create external file format command issued in SQL server
24332Delete external file format command issued in SQL server
24333Create external resource pool command issued in SQL server
24334Change external resource pool command issued in SQL server
24335Delete external resource pool command issued in SQL server
24337Global transaction login in SQL server
24349Change assembly owner command issued in SQL server

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.