Solved

Capture SQL Messages in text file

Posted on 2013-06-27
6
341 Views
Last Modified: 2013-10-07
When I run following command in SSMS query window,
exec test.dbo.sp_do_backups 'FULL', 'USER','C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\BACKUP\'  This SP takes backup of multiple dbs on server and it runs longer and generates following messages in message Pane as shown below.

DateTime: 2013-06-27 16:42:32
Server: TEST
Version: 9.00.5057.00
Edition: Enterprise Edition (64-bit)
Procedure: [test].[dbo].[p_dba_do_backups]
Parameters: @database_name = NULL, @backup_location = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\BACKUP\', @backup_type = 'FULL'
23 percent processed.
33 percent processed.
63 percent processed.
99 percent processed.
Processed 312 pages for database 'test', file 'test_Data' on file 1.
100 percent processed.
Processed 1 pages for database 'test', file 'test_Log' on file 1.
BACKUP DATABASE successfully processed 313 pages in 1.614 seconds (1.588 MB/sec).


However when I run the same SP  inside execute sql task in maintenance plan, I am not able to see above test. I need to store above data in some text file so that I can check that file if any error message is generated. Tell me the most simple way to do it using only SQL SERVER.
0
Comment
Question by:cottage125
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 16

Expert Comment

by:Surendra Nath
ID: 39283172
the simplest way in SQL Server is to change the above stored procedure, and put a try..catch block around it

and at the end of try block return 0 and at the end of catch block return 1.

Now, you try to handle the return value in your script task, ensure that it is 0, or else treat it as failure.
0
 
LVL 16

Expert Comment

by:EvilPostIt
ID: 39283646
If you execute this stored procedure from a SQL Server agent task, with the step that you would configure on the advanced tab there is an option called "Output file". This will allow you to save your output to file. Assuming you want to schedule it...
0
 

Accepted Solution

by:
cottage125 earned 0 total points
ID: 39284599
TO- Neo_jarvis Thanks but I am using execute SQL task from inside of maintenance plan and I dont see in the properties any return value related expression that I can set there. Can u explain me in more detail??
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:cottage125
ID: 39539741
No one has replied yet so closing this question.
0
 

Author Comment

by:cottage125
ID: 39539743
No one has replied yet so closing this question.
0
 

Author Closing Comment

by:cottage125
ID: 39551646
No one has replied yet so closing this question.
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

691 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