Monday, December 5, 2011

Determine WHEN and WHAT FILE was LAST Used to RESTORE a SQL SERVER Database

Sometimes you've restored a database from a production copy or whatever, and you move on to a different project.  Time goes by, and someone needs to run something on that database, but they need to know if the database has already been restored from a recent copy of production...  How do you find out when the last time a database was restored and what file was used to restore it?

This little script has been a HUGE time saver.  I use this script to determine if I need to have our IT group backup and download a copy of a production database.  If the database I'm looking at was recently refreshed from production already, I don't need them to waste that kind of time.  That can save us up to literally 24 hours in wasted time in some cases.

To run this, copy and paste this code into SQL Server Management Studio 2005 or greater (I think this works with SQL 2000 as well with Query Analyzer).  Don't forget to make sure you have the database selected in the dropdown list for which you want to find out this information:

DECLARE @backup_finish_date DATETIME
DECLARE @source_database_name VARCHAR(100)
DECLARE @restore_date DATETIME
DECLARE @backup_file_used_for_restore VARCHAR(500)

SELECT TOP 1 @restore_date = [rs].[restore_date],
             @backup_finish_date = [bs].[backup_finish_date],
             @source_database_name = [bs].[database_name],
             @backup_file_used_for_restore = [bmf].[physical_device_name]
FROM   msdb..restorehistory rs
       INNER JOIN msdb..backupset bs
         ON [rs].[backup_set_id] = [bs].[backup_set_id]
       INNER JOIN msdb..backupmediafamily bmf
         ON [bs].[media_set_id] = [bmf].[media_set_id]
WHERE  [rs].[destination_database_name] = Db_name()
ORDER  BY [rs].[restore_date] DESC

PRINT @@SERVERNAME + ' : ' + Db_name()

PRINT 'was restored on: ' + Isnull(CAST(@restore_date AS VARCHAR), 'No Date')

PRINT 'from a backup of database: ' + Isnull(@source_database_name, 'No Name')

PRINT 'taken on: ' + Isnull(CAST(@backup_finish_date AS VARCHAR), 'No Date')

PRINT 'in file: ' + Isnull(@backup_file_used_for_restore, 'No Name')  


The results will typically look like this:

CCGTESTDB\SQL2005 : stIowaProd
was restored on: Dec  5 2011  1:15PM
from a backup of database: db_CNPProd
taken on: Nov  8 2011  1:49PM
in file: E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\Iowa\db_CNPProd_201111081349\db_CNPProd_201111081349.bak


How do you determine this information?  Any better solution, please comment.

Saturday, December 3, 2011

5 All-Time Greatest Toys


The holidays come every year, and we stress over toys and gifts.  But some toys will always be the best...  follow to see the 5 all-time greatest toys ever.

Sunday, November 6, 2011

Windows Phone 7.1 SDK Error


I need your help! "GetCopyToOutputDirectoryContentProjectItems"

I went to a Microsoft Code Camp a few days ago and got all pumped up about the Windows Phone 7.1 release (Mango) SDK.  They handed it out to us. I installed it.  I have tried building many default projects but to no avail, I'm getting the following error:

The target "GetCopyToOutputDirectoryContentProjectItems" does not exist in the project.
WHAT DOES THIS MEAN???? I'm going to lose all my hair from this error.

I'm using the release candidate (not the beta 2, at least I don't think it is...) that was given to us at the Mango Code Camp here in AZ a few days ago.  I tried to uninstall, re-boot, re-install, re-boot.  And all combinations of the same.  Nothing is working.  There is something else I found strange:  Part of the install cannot install the XNA Game Studio plugin and some other XNA item.  I don't have the XNA Game Studio installed.  I' not sure if it the Windows Phone 7.1 SDK tris to install XNA GS or not, but I tried to manually install it and I' getting an error with that as well.  I think that it had to do with the live installer.  I uninstalled it too and tried to install again.  Still same error.  It seems like the project is fine (since this happens on ALL my Windows Phone Projects including one I've tried to target the 7.0 Windows Mobile.  Something seems like it's missing but I cannot figure it out. I'd be happy to send any log files if needed.

FYI, The 3 guys at MS that were there at the phone camp had never seen this error and didn't have any idea what to do other than re-install and re-boot.  No help.  PLEASE HELP!!!  Any other ideas?  Thanks!

Note:  I also uninstalled the Silverlight 4 SDK and even installed the Silverlight 5 SDK once it still did not work and both tries still did nothing to help resolve this.

Friday, February 11, 2011

Facebook and Android API Documentation

I recently integrated Facebook access into one of my android apps (My Missionary). It was the worst pain in the backside! Why, you ask? Because the documentation is not accurate. Documentation directly from Facebook! Its terrible. The only way I figured it out was through scouring the web all night long. And I mean all night. Then, I even had to modify some of the Facebook code (the library you can download from FB) in order to make it work! Oh well. I learned. I'll post my findings here so you don't have to waste a night of sleep...