Friday, June 18, 2021

How to restore DB from UAT to Dev D365 FO

Open CMD in administrator mode


Go to :

cd C:\Program Files\Microsoft SQL Server\150\DAC\bin

(i.e sometimes in 130)


Now create a new DB in SSMS (In my case name: AXDBFromUAT)


now run this command 

 SqlPackage.exe /a:import /sf:C:\DBFromUAT\SOLERPUATbackup.bacpac /tsn:localhost /tdn:AXDBFromUAT /p:CommandTimeout=32000

Please Note:

{

    If you are facing below error:

    *** Changes to connection setting default values were incorporated in a recent release.  More information is available at https://aka.ms/dacfx-connection

    *** Error importing database:Could not import package.

    Unable to connect to target server 'localhost'. Please verify the connection information such as the server name, login credentials, and firewall rules for the target server.

    A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)

    The certificate chain was issued by an authority that is not trusted.

    *** The settings for connection encryption or server certificate trust may lead to connection failure if the server is not properly configured.


    use below command
    SqlPackage.exe /a:import /sf:C:\DBFromUAT\SOLERPUATbackup.bacpac /tsn:localhost /tdn:AXDBFromUAT /p:CommandTimeout=32000 /ttsc:True

}

(your package is saved in C:\DBFromUAT\SOLERPUATbackup.bacpac)


Now rename the older DB from AXDB to AXDBOld 

and new DB from AXDBFromUAT to AXDB

using the following commands


USE master;  

GO  

ALTER DATABASE AxDBUAT SET SINGLE_USER WITH ROLLBACK IMMEDIATE

GO

ALTER DATABASE AxDBUAT MODIFY NAME = AxDB ;

GO  

ALTER DATABASE AxDB SET MULTI_USER

GO


Link

Renaming issue

{

SELECT * FROM sys.dm_exec_sessions WHERE database_id = DB_ID('AxDB');

then kill that process

}

for process errors during the renaming

run below query


select 

d.name, 

d.dbid, 

spid, 

login_time, 

nt_domain, 

nt_username, 

loginame

from sysprocesses p 

inner join sysdatabases d 

    on p.dbid = d.dbid

where d.name = 'AxDb'

GO


and kill that process