0

I have a C# windows Forms application and when the start-up Form loads, i want to check the last time a backup was performed on the database the application connects to.

2 Answers 2

1

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/

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.