Wednesday, December 5, 2018

D365FO - Can not rename database - The database could not be exclusively locked to perform the operation

Currently in D365 when importing a new dataset via the bacpac method you are supposed to import the data into a new database and then rename the old AxDB to something else and then rename the new AxDB_new to AxDB. In order to do this previously we would turn off the following services
  • Microsoft Dynamics 365 Unified Operations: Batch Management Service
  • Microsoft Dynamics 365 Unified Operations: Data Import Export Framework Service
  • Management Reporter 2012 Process Service
  • World Wide Web Publishing Service (IIS/W3SVC)

Which SHOULD which should drop all connections to the AxDB. However I am noticing that now (in 8.1+) there are still connections from axOnline, axSystem and a .net provider that I am not sure where they are coming from. Which will cause the error

Unable to rename AxDB

The database could not be exclusively locked to perform the operation.

I have tried putting the db into single user mode and restricted mode however the connections still happen. So in order to rename the databases and drop the connections you can use the following script which will wrap up everything into a single transaction and seems to work well



--set main db to single connections and drop the existing connections
ALTER DATABASE AxDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
--rename datbase to db_old
ALTER DATABASE AxDB MODIFY NAME = AxDB_old
--set the old db to multi user
ALTER DATABASE AxDB_old SET MULTI_USER
--rename the new db to the main db name
ALTER DATABASE AxDB_new MODIFY NAME = AxDB        

No comments:

Post a Comment