Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

Capture SQL Messages in text file

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
cottage125
Asked:
cottage125
  • 4
1 Solution
 
Surendra NathCommented:
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
 
EvilPostItCommented:
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
 
cottage125Author Commented:
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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
cottage125Author Commented:
No one has replied yet so closing this question.
0
 
cottage125Author Commented:
No one has replied yet so closing this question.
0
 
cottage125Author Commented:
No one has replied yet so closing this question.
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

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