Solved

How to write a SQL query to the errorlog

Posted on 2014-04-03
4
282 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
ID: 39975921
The built in procedure sp_readerrorlog will retrieve data from the error log.

Run EXEC sp_readerrorlog

Kelvin
0
 

Author Comment

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

Expert Comment

by:Kelvin Sparks
ID: 39976162
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:
Scott Pletcher earned 500 total points
ID: 39976367
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

828 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