Readme_Backup and Restore Sample

11/05/2008 21:36:06


This sample works only with SQL Server 2005 and SQL Server 2008. It will not work with any version of SQL Server earlier than SQL Server 2005.
The Backup and Restore sample lets you use Analysis Management Objects (AMO) to connect to a server that is running Microsoft SQL Server Analysis Services. The sample creates a new empty database, completes a backup of that database, deletes the database, restores the database from the backup, and deletes that database.

Scenario

This sample shows you how to back up and restore your Analysis Services databases programmatically.

Languages

C#

Features

The Analysis Services sample uses the following items.

Application area Features
AMOAdventureWorks AMO Objects


Prerequisites

Before you run this sample, you must have the following software installed:
  • .NET Framework SDK 2.0 or Microsoft Visual Studio 2005. You can obtain .NET Framework SDK free of charge. For more information, see Installing the .NET Framework SDK in SQL Server Books Online.
  • Analysis Services
  • Business Intelligence Development Studio Note: Business Intelligence Development Studio is not supported on computers that run the Itanium-based operating system; the 64-bit development environment is supported on x64-based operating systems. SQL Server samples can be modified and run on computers that run either x86 or x64-based operating systems when databases used by the samples are deployed on an Itanium-based operating system.
  • The AdventureWorks AS database. You can download this sample database from the Microsoft SQL Server Samples and Community Projects web site. For more information about how to download and install sample databases, see Installing SQL Server Samples and Sample Databases in SQL Server Books Online. After your sample has been successfully compiled, you have to access one of the Analysis Services sample databases to test your program. We recommend that you use the AdventureWorks sample database that is provided with SQL Server.
User Permissions for Backup
For each backup file, the user who runs the backup command must have permission to write to the backup location specified. Also, the user must have one of the following roles: a member of a server role for the Analysis Services instance, or a member of a database role with Full Control (Administrator) permissions on the database to be backed up.
User Permissions for Restore
For each backup file, the user who runs the restore command must have permission to read from the backup location specified. To restore an Analysis Services database that is not installed on the server, the user must also be a member of the server role for that Analysis Services instance. To overwrite an Analysis Services database, the user must have one of the following roles: a member of the server role for the Analysis Services instance, or a member of a database role with Full Control (Administrator) permissions on the database to be restored.

Note:
After restoring an existing database, the user who restored the database might lose access to the restored database. This loss of access can occur if, at the time that the backup was performed, the user was not a member of the server role or was not a member of the database role with Full Control (Administrator) permissions.



Building the Sample

If you have not already created a strong name key file, generate the key file using the following instructions.
To generate a strong name key file
  1. Open a Microsoft Visual Studio 2005 command prompt. Click Start, point to All Programs, point to Microsoft .NET Framework SDK 2.0, and then click SDK Command Prompt.-- or --Open a Microsoft .NET Framework command prompt. Click Start, point to All Programs, point to Microsoft .NET Framework SDK 2.0, and then click SDK Command Prompt.
  2. Use the change directory command (CD) to change the current directory of the command prompt window to the folder where the samples are installed. Note: To determine the folder where samples are located, click the Start* button, point to All Programs, point to Microsoft SQL Server, point to Documentation and Tutorials, and then click Samples Directory. If the default installation location was used, the samples are located in <system_drive>:\Program Files\Microsoft SQL Server\100\Samples.*
  3. At the command prompt, run the following command to generate the key file: sn -k SampleKey.snk Important: For more information about the strong-name key pair, see "Security Briefs: Strong Names and Security in the .NET Framework" in the .NET Development Center on MSDN.
To build the Backup and Restore sample
  • Build the sample by using Visual Studio 2005 and the provided Visual Studio solution.— or —
  • Build the sample using Microsoft MSBuild, which is included in the .NET Framework SDK 2.0, and run a command similar to the following at a command prompt: msbuild /nologo /verbosity:quiet /property:Configuration=Debug CS/BackupAndRestore.sln Other Microsoft MSBuild build options can be used depending on your needs.

Running the Sample

To run the Backup and Restore sample
  • In Visual Studio 2005, press F5.— or —
  • In Visual Studio 2005, click Start on the Debug menu.— or —
  • At a command prompt, run a command similar to the following: CS\BackupAndRestore\bin\Debug\BackupAndRestore.exe The path might vary depending on the options that were used to compile the sample and the starting folder when at command prompt.After you run the sample, the backup file of the temporary database created by the sample will be located at <systemdrive>:\backupfilegeneratedbyAMOsamplecode.abf.

See Also

Tasks
Readme_DisplayObjectNames Sample
Concepts
Analysis Services Multidimensional Database Samples
Help and Information
  • Getting SQL Server 2008 Assistance* © 2008 Microsoft Corporation. All rights reserved.

Last edited Mar 19, 2009 at 3:51 AM by libinzhao, version 9

Comments

No comments yet.