473,385 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to email completion messages from RESTORE commands?

I need to build an automated email that gives the completion messages
when a database is restored (i.e. "Executed as user: sa. Executing
RESTORE DATABASE DB1 FROM
DISK='h:\backups\DB1\DB1_db_200411082056.BAK', RECOVERY [SQLSTATE
01000] (Message 0) Processed 3816 pages for database 'DB1', file
'DB1_Data' on file 1. [SQLSTATE 01000] (Message 4035) Processed 1
pages for database 'DB1', file 'DB1_Log' on file 1. [SQLSTATE 01000]
(Message 4035)")

Currently, the Job History box contains it, but I'd rather get it via
email. The base restore statement works, but it gives me a "Cannot
perform a backup or restore operation within a transaction." when I
try to run it as below.

works:
[build @RestoreCmd]
exec (@RestoreCmd)

doesn't:
[build @RestoreCmd]
create table #Error_Finder (listing nvarchar (4000))
declare @Errors smallint
insert #Error_Finder exec (@RestoreCmd)
EXEC xp_sendmail @recipients = 'dba',
@query = 'SELECT * from #Error_Finder',
@subject = 'SQL Server Restores'
drop table #Error_Finder
Any suggestions? My next thought is to start selecting against system
tables in msdb. It looks because the Insert can fail, it's a
transaction.
Jul 20 '05 #1
2 1896
Michale
In advanced tab of the job step window click 'edit' there you can define
where to go in success or on failure. Create two steps like 'send OK', and
'send Failed' that will be notified you about restore.


"Michael Bourgon" <bo*****@gmail.com> wrote in message
news:55**************************@posting.google.c om...
I need to build an automated email that gives the completion messages
when a database is restored (i.e. "Executed as user: sa. Executing
RESTORE DATABASE DB1 FROM
DISK='h:\backups\DB1\DB1_db_200411082056.BAK', RECOVERY [SQLSTATE
01000] (Message 0) Processed 3816 pages for database 'DB1', file
'DB1_Data' on file 1. [SQLSTATE 01000] (Message 4035) Processed 1
pages for database 'DB1', file 'DB1_Log' on file 1. [SQLSTATE 01000]
(Message 4035)")

Currently, the Job History box contains it, but I'd rather get it via
email. The base restore statement works, but it gives me a "Cannot
perform a backup or restore operation within a transaction." when I
try to run it as below.

works:
[build @RestoreCmd]
exec (@RestoreCmd)

doesn't:
[build @RestoreCmd]
create table #Error_Finder (listing nvarchar (4000))
declare @Errors smallint
insert #Error_Finder exec (@RestoreCmd)
EXEC xp_sendmail @recipients = 'dba',
@query = 'SELECT * from #Error_Finder',
@subject = 'SQL Server Restores'
drop table #Error_Finder
Any suggestions? My next thought is to start selecting against system
tables in msdb. It looks because the Insert can fail, it's a
transaction.

Jul 20 '05 #2
[posted and mailed, please reply in news]

Michael Bourgon (bo*****@gmail.com) writes:
Currently, the Job History box contains it, but I'd rather get it via
email. The base restore statement works, but it gives me a "Cannot
perform a backup or restore operation within a transaction." when I
try to run it as below.

works:
[build @RestoreCmd]
exec (@RestoreCmd)

doesn't:
[build @RestoreCmd]
create table #Error_Finder (listing nvarchar (4000))
declare @Errors smallint
insert #Error_Finder exec (@RestoreCmd)
EXEC xp_sendmail @recipients = 'dba',
@query = 'SELECT * from #Error_Finder',
@subject = 'SQL Server Restores'
drop table #Error_Finder


Even if there is no user-defined transaction, an INSERT, UPDATE or
DELETE statement is its own transaction in SQL Server. This means that
INSERT EXEC() defines a transaction.

Furthermore, even if RESTORE had not cared about the transaction, it
would not have worked anyway, because INSERT EXEC() can only catch
result set, and what RESTORE produces is an informational message,
which is passed to the client. There is no way to catch this message
in the server.

Uri's suggestion of using the GUI to set up a e-mail alert, sounds like
a much easier way to go.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Edvard Majakari | last post by:
Suppose you have a program containing commands and file name parameters. A simple class providing completion could first read all the commands to list, and extend that list later using all file...
3
by: Tim Morrison | last post by:
MSDE2000 I have an application in which I am running a TSQL command of BACKUP DATABASE and RESTORE DATABASE for the backup and restore commands for my application. For testing purposes, i did the...
2
by: anna_cheng11 | last post by:
We do not have a DBA available, and this is a development environment, hence I was asked to do the work. I am not a DBA. I need some help to clarify my understanding of DB2 recovery and I am...
2
by: Buck Turgidson | last post by:
I have an SAP development system running on Linux. It is not a critical system, but I would like a restore-able backup. I have taken an offline backup, but I am unable to restore it. I am...
4
by: Rob Richardson | last post by:
Greetings! I am trying to write a set of macros to generate Property code for private variables. With the cursor on a line that says "Private m_MyThing as Thing", I would run the macro and ...
0
by: Takpol | last post by:
Hello, I have several archived filegroups that have data in them partitioned based on the date. These filegroups have been removed from database after archival. For example two months ago....
4
by: aj | last post by:
DB2 LUW v8.2 FP 14 RHAS 2.1 I have a DB2 online DB backup that was done w/ the INCLUDE LOGS option. I am interested in restoring that backup, and rolling forward ONLY the logs contained in the...
1
by: nikb | last post by:
I am trying to restore a SQL Server database from a .dat file. An earlier question on how to do this elicited the following answer. " You need to know how the '.dat' file was created in order...
4
by: pinoy2ser | last post by:
hello All, im not a db2 person, please forgive me for asking a simple question.. i would like to restore a tablespace from a current database to a new database in the same server how do i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.