When trying to do a restore, if any other active connection is established with database you will see these types of error messages:
System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in use. (Microsoft.SqlServer.Smo)
Resolution:
Make the database in single user mode and then do the restore
ALTER DATABASE AdventureWorks SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO RESTORE DATABASE AdventureWorks FROM DISK = 'C:\AdventureWorks.BAK' GO