There are times when you will need to synchronize the database to test development changes, resolve SQL errors, or fix other issues in D365. In this article I will discuss the different ways to synchronize the database.
First I will explain why synchronizing the database is important and when it needs to be done.
Then I will walk through the steps required to synchronize the database in tier 1 environments.
Finally I will discuss synchronizing the database in tier 2 and production environments.
Why synchronize the database?
The synchronization process creates all of the tables that Microsoft Dynamics needs to operate. The most common reason to synchronize the database is during development. Anytime that a change is made to a table, table extension, or data source the database will need to be synchronized before the changes will apply to the environment. Therefore this step is unavoidable as it will be required to test any changes that have been made involving the database. Another common scenario where it is necessary to synchronize the database is if SQL errors are being encountered in the front end.
How to Synchronize the database in a tier 1 environment
There are several ways to synchronize the database in a tier 1 environment, and each of them have their own advantages and distadvantages.
The first and most straightforward method is by using the Dynamics 365 menu at the top of the page in Visual Studio. Under this menu there is a “Synchronize database” option that can also be accessed by using the hotkey Ctrl+R, Ctrl+D. When you synchronize the database using this method, all database objects in the system will be synchronized. This process can take as little as ten minutes, or well over an hour depending on the size of the database being used.
Synchronize the Database from a project
The second method is to synchronize the database in the scope of a project. To do this, open a project to view it in the solution explorer. Once your project is open, right click on it and select the “Synchronize Project_Name [Model_Name] with database” option. This will synchronize only the database objects included in the project. Since this is a much smaller subset of data, this process will take a fraction of the time.
Synchronize the database on build
Another option for synchronizing the database is to set the “Synchronize database on build” project property equal to True. This can be done by right clicking on a project from the solution explorer and selecting the “Properties” option.
With this property set, the database objects in the project will be synchronized anytime the project is built. This can be very helpful for developers as they won’t need to worry about remembering to synchronize the database every time they make a change.
Synchronize the database using command line
Another very important way to synchronize the database is by using the command line. To do this, open the command prompt as and administrator and enter the following commands.
K:
cd K:\AosService\WebRoot\bin\
SyncEngine.exe -syncmode=fullall -metadatabinaries=K:\AosService\PackagesLocalDirectory -connect="Data Source=LOCALHOST;Initial Catalog=AxDB;Integrated Security=True;Enlist=True;Application Name=SyncEngine" -fallbacktonative=False -raiseDataEntityViewSyncNotification >log.txt 2>&1
Notepad log.txt
This will run a full sync of all database objects similar to the “Synchronize database” option from the Dynamics 365 menu outlined above. Additionally, a log file will be populated with much greater detail than is provided when synchronizing the database through visual studio. This method of synchronizing the database will frequently succeed even when synchronizing through Visual Studio has failed. Due to this fact, I always recommend this as the first thing to try when a database sync is failing. If there are further issues, the details in the log file should be able to point you towards the root cause.
Database Syncs in tier 2 and production environments
Synchronizing the database in tier 2 and production environments is required very infrequently. However it is just as important to have a good understanding of how it works and what steps to take. The most common way that a database is synchronized in a tier 2+ environment is by applying a deployable package through LCS. All database objects will be synchronized automatically as part of this process. This will ensure that the database lines up with any code changes that might have occurred. The other way to synchronize the database in a tier 2+ environment is by enabling maintenance mode. As part of this process, all database objects will be synchronized automatically. For steps on enabling Maintenance mode, please keep an eye out for my upcoming article.
Conclusion
There are many different ways to synchronize the database in D365, and the best method to use will vary based on the environment and situation you are faced with. I hope this article has helped enrich your understanding of the subject matter. Please feel free to chime in below with any questions or comments.
Leave a Reply