Dynamics 365 LCS tricks – restoring database

Microsoft supports the possibility to restore a database from Production to any azure database in your hosted environment. In case this database needs to be pushed to Production (go live) a special request must be sent.  In this article I will explain what to do for the local VM


One can follow the instructions from https://ax.help.dynamics.com/en/wiki/copy-an-ax-database-from-azure-sql-database-to-sql-server/
But what is happening at the low level, it is not an ordinary backup restore operation as we have been used to see in older Dynamics AX environments.
For more information, one should read the next link https://docs.microsoft.com/en-us/azure/sql-database/sql-database-copy. It is good to note that the backup type is now a BACPAC file. One of the additional steps that Microsoft executes is disabling all the users except for the admin user. After the restore all user will not be able to login. I have created the SQL instruction below to enable all the required users with admin rights.
update userinfo set enable = 1
where id in (select User_ from SECURITYUSERROLE
where SECURITYROLE in (select recid from SECURITYROLE
where SECURITYROLE.aotname = ‘-SYSADMIN-‘ ))

Trouble shooting

Login on SQL:

I always login on the BI server because Sql Studio is installed on that server. The connection to the database is also a little different. See the screen dump below.  One has to add ‘. database.windows.net’ at the end of the SQL server name. The SQL server name and login user are shown in LCS

So login this way.

 

Data access Errors

  • After restoring the database there is a possibility that one will encounter these kinds of errors.
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : The server principal “axdeployuser” is not able to access the database “master” under the current security context..
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Login failed for user ‘axdeployuser’..
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Cannot open user default database. Login failed..

This error is related to the orphan users – usernames being correct but the users’ SPID are different. These have to be removed from the database and hooked in again.

CREATE USER axdeployuser FROM LOGIN axdeployuser  EXEC sp_addrolemember ‘db_owner’, ‘axdeployuser’

In the remote case that this does not work, make sure to remove the users everywhere – on security and on system databases. In this unfortunate event, the users have to be recreated from scratch.

The password is shown on the environment’s LCS.

CREATE LOGIN axdeployuser WITH PASSWORD = IkIi*2jG!MpQE’;
CREATE USER axdeployuser FROM LOGIN axdeployuser;

some minor tweaks

  • Change on the restored DB the recovery model to simple and also enable the change tracking
  • One might still encounter issues, like not being able to synchronize the database from Visual studio. Check in the windows event log for errors similar to the one shown below:

    This means that the environment must be patched.
Comments1

Leave a Comment!

Your email address will not be published. Required fields are marked *