Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

IDbBackupManager.CreateBackup Method

IIS 7.0

Creates a database backup.

Namespace:  Microsoft.Web.Management.DatabaseManager
Assembly:  Microsoft.Web.Management.DatabaseManager (in Microsoft.Web.Management.DatabaseManager.dll)
void CreateBackup(
	string connectionString,
	string backupPath


Type: System.String
The connection string for the database.
Type: System.String
The path of the backup to create.

All implementations of the IDbBackupManager interface must also implement the CreateBackup method, which the database manager will use to create database backups.

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

        // Create a database backup.
        public void CreateBackup(string connectionString, string backupPath)
            // Create a connection to the database.
            using (OleDbConnection connection = new OleDbConnection(connectionString))
                    // Verify that the source database path is not the same as the backup path.
                    if (connection.DataSource.Equals(backupPath, StringComparison.OrdinalIgnoreCase))
                        // Raise an exception that the database file paths cannot match.
                        throw new ArgumentException("The database backup path cannot match the source path.");
                        // Copy the database file to the backup path.
                        File.Copy(connection.DataSource, backupPath, true);
                catch (Exception ex)
                    // Raise an exception if an error occurs.
                    throw new ProviderException(ex.Message);
                    // Close the database connection.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.