Search your query

Thursday, September 12, 2019

Restore DB in Development Environment by using BACPAC File



> Copy the bacpac file in your development environment.

> Open Command Prompt in Administrator

> Copy the below command and paste into Command Prompt and Enter

      > cd C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin

> Copy the below another command and paste into Command Prompt and Enter

        > SqlPackage.exe /a:import /sf:J:\AlreadyTakenBackup.bacpac /tsn:localhost /tdn:NewTargetDB /p:CommandTimeout=2400

> You might get the message when this above command is executed successfully.

> Stop all Dynamics related services and including IIS service.

> Now Open the SQL Server and rename the AXDB database into different name and again rename the "NewTargeDB" into "AXDB" Database.



NOTE: If you are unable to find this folder : C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin then,

> Open this website and download the latest sql package: https://docs.microsoft.com/en-us/sql/tools/sqlpackage/sqlpackage-download?view=sql-server-ver15

> download above file into "TEMP" folder by selecting "Save As"

> Open Temp folder > (latest) > Sql Package folder > Select File Menu and click "Open Command Prompt As Administrator" and then paste the below code:

SqlPackage.exe /a:import /sf:J:\AlreadyTakenBackup.bacpac /tsn:localhost /tdn:NewTargetDB /p:CommandTimeout=1200

NOTE: The above comment will be giving some error for latest SQL Package so we need to add /ttsc:true this command also in import SQL Pakage command.

For Example:

SqlPackage.exe /a:import /sf:J:\AlreadyTakenBackup.bacpac /tsn:localhost /tdn:NewTargetDB /ttsc:true /p:CommandTimeout=1200



For EXPORT bacpac FILE:

Example Code:

> SqlPackage.exe /a:export /ssn:localhost /sdn:AxDB /tf:C:\NewDatabaseFileName.bacpac /p:CommandTimeout=1200 /p:VerifyFullTextDocumentTypesSupported=false

> That's it.


Latest Update: Year: 2025

Include DB Premium edition to avoid error when importing bacpac file.

Example:
SqlPackage.exe /a:import /sf:C:\NewDatabaseFileName.bacpac /tsn:localhost /tdn:NewTargetDB /ttsc:true /p:CommandTimeout=1200 /p:DatabaseEdition=Premium /tu:"sqladmin" /tp:"yourPassword"