IDbRestoreManager.RestoreBackup Method

IIS 7.0

Restores a database backup.

Namespace:  Microsoft.Web.Management.DatabaseManager
Assembly:  Microsoft.Web.Management.DatabaseManager (in Microsoft.Web.Management.DatabaseManager.dll)

void RestoreBackup(
	string connectionString,
	string backupPath
)

Parameters

connectionString
Type: System.String
The connection string for the database.
backupPath
Type: System.String
The path of the backup to restore.

All implementations of the IDbRestoreManager interface must also implement the RestoreBackup method. The database manager will use this method to restore database backups.

The following code sample implements the RestoreBackup method for an OLEDB connection by using the connection string and backup path that the database manager provides.



        // Restore a database backup.
        public void RestoreBackup(string connectionString, string backupPath)
        {
            // Create a connection to the database.
            using (OleDbConnection connection = new OleDbConnection(connectionString))
            {
                try
                {
                    // Verify that the backup path exists.
                    if (File.Exists(backupPath))
                    {
                        // Copy the backup path over the database file.
                        File.Copy(backupPath, connection.DataSource, true);
                    }
                    else
                    {
                        // Raise an exception that the database backup cannot be found.
                        throw new ArgumentException("The database backup path does not exist.");
                    }
                }
                catch (Exception ex)
                {
                    // Raise an exception if an error occurs.
                    throw new ProviderException(ex.Message);
                }
                finally
                {
                    // Close the database connection.
                    connection.Close();
                }
            }
        }



Show: