473,698 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:\backup s\DB1\DB1_db_20 0411082056.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 1907
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.goo gle.com...
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:\backup s\DB1\DB1_db_20 0411082056.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****@sommarsk og.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
1624
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 names in given directory. This way a user could tab-complete (using readline.parse_and_bind('tab: complete')) any command and any file. Eg. if a command 'move' is implemented and there are files 'foo.txt' and 'bar.txt', the user could type ...
3
9107
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 following: 1) Ran a BACKUP DATABASE command to a file named C:\TEST.BAK. 2) Deleted the database completely. 3) Ran a RESTORE DATABASE on the same file (note, I did NOT recreate the database) Now I have the database back with all my data....
2
4139
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 reading the following as well. http://publib.boulder.ibm.com/infocenter/db2help/index.jsp I have a database say DB_INV on machine A and the database is backed up to tape, I am going to create a second system, say machine B with a database called...
2
7302
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 guessing I need to quiesce the database somehow and get it into an offline state. What are commands to do so in db2? This is what I get when Itry to restore.
4
1058
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 Public Property MyThing() As Thing Get Return m_MyThing End Get
0
3145
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. Meantime my production database is populating everyday. Now I would like to restore one of my old archived filegroups. In order to do that I would like to backup and restore the current Primary filegroup to another server, and also restore the...
4
20486
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 backup and no more, then bringing the DB online. I do not want to use a userexit to try and retrieve additional logs - I only want to roll forward the logs in the backup. (In case you haven't guessed, I am restoring a test version of my
1
7097
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 to import it. Use RESTORE FILELISTONLY to determine if this is a database backup: RESTORE FILELISTONLY FROM DISK='C:\MyDatabase.dat'
4
6458
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 accomplish this task. I use tsm to backup my db... i was looking around web and found instruction to the restore command in db2...
0
8676
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9161
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.