The "create web application" function does the following steps:
- Check if Site Collection exists
- If it doesn't, create Content DB
- Create site collection
The problem is if I want to attach a content DB that already exists and contains site collections. When the content DB is attached, the site collection "springs into existence"
So the script checks for the site collection - it's not there. It creates (attaches) the content DB, which adds the site collection to the web app. Then when the script tries to create the site collection, it errors out (and fails)
You need to test for the existence of the site collection again *after* the database is attached. Alternatively, Fail gracefully, log the issue, and keep going.
- Check if Site Collection exists
- If it doesn't, create Content DB
- Create site collection
The problem is if I want to attach a content DB that already exists and contains site collections. When the content DB is attached, the site collection "springs into existence"
So the script checks for the site collection - it's not there. It creates (attaches) the content DB, which adds the site collection to the web app. Then when the script tries to create the site collection, it errors out (and fails)
You need to test for the existence of the site collection again *after* the database is attached. Alternatively, Fail gracefully, log the issue, and keep going.