| |



|
|
| Getting Started with SMO in SQL 2005 - Verifying Backups |
| Author |
Jasper Smith |
Hits |
6234 |
| Create Date |
30-08-2004 |
Last Updated |
08-08-2007 |
| Versions |
SQL2005 |
|
|
Overview
In this series of articles, I'll demonstrate
how to use SMO (SQL Management Objects) to do a variety of common DBA tasks
including Backups, Restores,Index Maintenance, Integrity checks and more. These
are some of the operations available in the SMO database maintenance utility
available on this site - ExpressMaint. In
this article we will concentrate on how to verify backups using SMO in SQL2005.
For information on how to build and compile a SMO application please review Getting
Started with SMO in SQL 2005.
Verifying Backups
In order to perform a verify using SMO we
require two objects, a Server object and a Restore object. In its simplest
form, a Restore object requires only a few properties to be set before calling
the SqlVerify method and passing in the Server object as can be seen in the
following example that does a verify of a database backup from the file c:\SMOTest.bak.
This example uses the overloaded SqlVerify method to return the verify error
if the method returns false.
[Visual Basic]
Imports Microsoft.SqlServer.Management.Smo
Module SMOTest
Sub Main()
Dim svr As Server = New Server()
Dim res As Restore = New Restore()
Dim verified As Boolean
Dim errormsg As String = ""
res.Devices.AddDevice("C:\SMOTest.bak", DeviceType.File)
verified = res.SqlVerify(svr, errormsg)
Console.WriteLine("verified = " & verified.ToString())
If verified = False Then
Console.WriteLine(errormsg)
End If
End Sub
End Module
[C#]
using System;
using Microsoft.SqlServer.Management.Smo;
namespace SMOTest
{
class Program
{
static void Main()
{
Server svr = new Server();
Restore res = new Restore();
Boolean verified;
String errormsg;
res.Devices.AddDevice(@"C:\SMOTest.bak", DeviceType.File);
verified = res.SqlVerify(svr, out errormsg);
Console.WriteLine("verified = " + verified.ToString());
if (verified == false)
Console.WriteLine(errormsg);
}
}
} |
Related Articles
Getting Started with SMO in SQL 2005
Getting Started with SMO in SQL 2005 - Backups
Getting Started with SMO in SQL 2005 - Restores
Getting Started with SMO in SQL 2005 - Integrity Checks
|
|