简体   繁体   中英

Check last Database backup date in C# - SQL Server 2008

我有一个C#Windows窗体应用程序,当启动窗体加载时,我想检查上次在应用程序连接到的数据库上执行备份。

you could create a store procedure that does the work for you. then you can execute it within the form's OnLoad event or where ever it fits for your need.

Have a look at the below for getting the T-SQL that does the trick

http://www.mssqltips.com/sqlservertip/1601/script-to-retrieve-sql-server-database-backup-history-and-no-backups/

These are taken from my automation of backups:

First get a list of all databases, including their database GUID:

select db.name, db.database_id, rec.database_guid
  from sys.databases db
    inner join sys.database_recovery_status rec on db.database_id = rec.database_id
  where db.source_database_id is null and db.name <> 'tempdb'

The condition on source_database_id excludes snapshots.

Then using the GUID from the above, get the date of the last full backup type='D' that isn't COPY_ONLY :

SELECT MAX(backup_finish_date) as backup_finish_date
  from msdb..backupset
  where type='D' and database_guid = @DbGuid and is_copy_only=0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM