I was configuring SharePoint app catalog service applications the other day using my old scripts for that, and there is one problem I often see when using PowerShell scripts for configuring SharePoint: those work much better as they save your time you may spend on wading through cumbersome GUI, but in case when you need to re-run this script once again (let’s say it failed in the middle as you not updated some of the variables with proper values, or forgot to adjust something in line with your naming convention), you are often in trouble as you need to clear up things created by the script before you will be able to re-run it without errors.
Normally (especially if you fully understand what your script actually does) it is not a big problem, but this time when creating App Management Service Application I run into this error:
New-SPAppManagementServiceApplication : A SharePoint database named SP2013_AppManagementSvc already exists. You must supply another
name for the new database.
Looks like straightforward error which prompts to fire off SSMS and drop DB in question and I think I did it before, but this time there was NO such DB on SQL server yet I keep receiving this error. A bit of Googling showed me that I just have a reference to this DB in Objects table of SharePoint configuration database. So we can use SQL script (GitHub link) to search and if necessary remove it:
--Check if reference to DB exist SELECT * FROM Objects WHERE name='SP2013_AppManagementSvc'; --Drop DB reference if necessary DELETE FROM Objects WHERE name='SP2013_AppManagementSvc';
Little quick fix, but as usual in case it is anything like production environment better take DB backup before messing with anything in it.