Solved

How to write a SQL query to the errorlog

Posted on 2014-04-03
4
274 Views
Last Modified: 2014-04-18
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
Comment
Question by:barnesco
  • 2
4 Comments
 
LVL 22

Expert Comment

by:Kelvin Sparks
Comment Utility
The built in procedure sp_readerrorlog will retrieve data from the error log.

Run EXEC sp_readerrorlog

Kelvin
0
 

Author Comment

by:barnesco
Comment Utility
I want to write to the log, not retrieve it.
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
Comment Utility
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
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 500 total points
Comment Utility
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now