What are you doing in the middle of setting your databases?
There is no need for the if statement when switching databases. Just switch them as the WorkingDatabase will not be the new database that you create. Additionally, once you switch it to the db database you know for a fact that it is not the workdb so switch it back.
HostApplicationServices.WorkingDatabase = db
'-----------------------------------------------
'Write Code to do something here
'-----------------------------------------------
HostApplicationServices.WorkingDatabase = workDb
If you are for sure using 2016 you can use the new Audit function that came with 2015 and call it before you save the drawing. That works for me sometimes. Make sure you reference Autodesk.Autocad.ApplicationServices.DatabaseExtensions if your using VB.
I did have this issue in the past and will try to see if i can find what actually caused it. I am pretty sure that it had something to do with me using the wrong database at somepoint while working in a side database.