• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

How to write a SQL query to the errorlog

How would you write a SQL query result or a job output to the SQL errorlog? There's a program that needs to read a backup failure/success from the errorlog.
0
barnesco
Asked:
barnesco
  • 2
1 Solution
 
Kelvin SparksCommented:
The built in procedure sp_readerrorlog will retrieve data from the error log.

Run EXEC sp_readerrorlog

Kelvin
0
 
barnescoAuthor Commented:
I want to write to the log, not retrieve it.
0
 
Kelvin SparksCommented:
Sorry misunderstood you as you said

There's a program that needs to read a backup failure/success from the errorlog.

The success/failure of backups is already in the SQL Server logs and can be extracted with the inbuilt sp above
0
 
Scott PletcherSenior DBACommented:
You can use RAISERROR(...) WITH LOG

Restrictions:
The message is limited to 440 bytes AND
User issuing the RAISERROR must have ALTER TRACE permissions (or be a sysadmin)


You should also review these trace flags and see if they give you want you need:
3605
4032
If you use them, I would strongly urge you NOT to make them global settings, but only for your session; that is, do NOT include -1 in the values when setting these trace flags.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now