如何使用C#计算已备份数据库的天数已过期 [英] How to count the number of days of the taken back up database is old using C#

查看:87
本文介绍了如何使用C#计算已备份数据库的天数已过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一条消息,您备份数据库已有15天了,请备份.
BackUP的代码-

I want to display a message that, you take a backup of database is 15 day old, please take a backup.
Code for BackUP-

public static void BackupDB(string backupDestinationFilePath)
        {
            try
            {
               // Console.WriteLine("Backup operation started");
                Backup backup = new Backup();
                //Set type of backup to be performed to database
                backup.Action = BackupActionType.Database;
                backup.BackupSetDescription = "BackupDataBase description";
                //Set the name used to identify a particular backup set.
                backup.BackupSetName = "Backup";
                //specify the name of the database to back up
                backup.Database = "DB_Jaggry";
                //Set up the backup device to use filesystem.
                BackupDeviceItem deviceItem = new BackupDeviceItem(
                                                backupDestinationFilePath,
                                                DeviceType.File);
                backup.Devices.Add(deviceItem);

                // Setup a new connection to the data server
                ServerConnection connection = new ServerConnection();               
                Server sqlServer = new Server(@"SNEHA-PC\SQLEXPRESS");
                //Initialize devices associated with a backup operation.
                backup.Initialize = true;
                backup.Checksum = true;               
                backup.ContinueAfterError = true;               
                backup.LogTruncation = BackupTruncateLogType.Truncate;                
                backup.SqlBackup(sqlServer);
               MessageBox.Show("Backup operation succeeded");
            }
            catch (Exception ex)
            {                
                MessageBox.Show(ex.ToString());
            }           
        }

推荐答案

这应该可以帮助您从C#进行备份:
SQL Server Express自动备份控制台应用程序C#ADO.NET [ ^ ]

获取上次备份日期:
http://stackoverflow.com/questions/7583817/check-last-database-backup-date-in-c-sharp-sql-server-2008 [
This should help you doing a back up from C#:
SQL Server Express Automated Backup Console Application C# ADO.NET[^]

To get the last backup date:
http://stackoverflow.com/questions/7583817/check-last-database-backup-date-in-c-sharp-sql-server-2008[^]

Now all that is left is to calculate the days :)


这篇关于如何使用C#计算已备份数据库的天数已过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆