Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Restores a database backup.
Namespace: Microsoft.Web.Management.DatabaseManager
Assembly: Microsoft.Web.Management.DatabaseManager (in Microsoft.Web.Management.DatabaseManager.dll)
Syntax
'Declaration
Sub RestoreBackup ( _
connectionString As String, _
backupPath As String _
)
'Usage
Dim instance As IDbRestoreManager
Dim connectionString As String
Dim backupPath As String
instance.RestoreBackup(connectionString, _
backupPath)
void RestoreBackup(
string connectionString,
string backupPath
)
void RestoreBackup(
String^ connectionString,
String^ backupPath
)
function RestoreBackup(
connectionString : String,
backupPath : String
)
Parameters
- connectionString
Type: System.String
The connection string for the database.
- backupPath
Type: System.String
The path of the backup to restore.
Remarks
All implementations of the IDbRestoreManager interface must also implement the RestoreBackup method. The database manager will use this method to restore database backups.
Examples
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 Sub RestoreBackup( _
ByVal connectionString As String, _
ByVal backupPath As String) _
Implements Microsoft.Web.Management.DatabaseManager.IDbRestoreManager.RestoreBackup
' Create a connection to the database.
Dim connection As OleDbConnection = New OleDbConnection(connectionString)
Try
' Verify that the backup path exists.
If File.Exists(backupPath) Then
' 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.")
End If
Catch ex As Exception
' Raise an exception if an error occurs.
Throw New ProviderException(ex.Message)
Finally
' Close the database connection.
connection.Close()
End Try
End Sub
// 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();
}
}
}
Permissions
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.