Solved

How to write a SQL query to the errorlog

Posted on 2014-04-03
4
281 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

832 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