I have added what was suggested:
IF DATABASEPROPERTYEX('archer', 'Status') = 'ONLINE'
BEGIN
use archer
SET NOCOUNT ON
END
It looks good until you execute and I get this error:
Msg 954, Level 14, State 1, Line 3
The database "Archer" cannot be opened. It is acting as a mirror database.