Hi,@Santhosh Badam. Welcome to Microsoft Q&A.
When you click a button/link, refresh the database connection. You could refer to the following method to do so.
<Button Click="Button_Click" Content="Refresh Connection" Height="50" Width="200"></Button>
MainWindow
public partial class MainWindow : Window
{
MainWindowViewModel mainWindowViewModel = new MainWindowViewModel();
public MainWindow()
{
InitializeComponent();
this.DataContext = mainWindowViewModel;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
mainWindowViewModel.Refresh_Connection();
}
}
MainWindowViewModel
public class MainWindowViewModel
{
private static readonly MyDbContext dbContext = new MyDbContext();
public void Refresh_Connection()
{
dbContext.Database.Connection.Close();
dbContext.Database.Connection.Open();
}
}
Load the backup database. You could create another dbcontext class and use the dbcontext to use the backup database.
If the structure of the backup database is the same as that of the original database, you could consider only modifying the connection string to use the backup database
dbContext.Database.Connection.ConnectionString = "Back up the database connection string";
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.