Thursday 19 March 2015

restore the data base through code(query)


Restore the database through query in ssms:

restore database MicrosoftDynamicsAX from disk='C:\SBX db_backUp\MOPR_AXSBX_01_comp.bak' with replace



if u will get this error like:



Msg 3102, Level 16, State 1, Line 1
RESTORE cannot process database 'MicrosoftDynamicsAX' because it is in use by this session. It is recommended that the master database be used when performing this operation.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.


use this command to restore the database:

USE master
GO

restore database MicrosoftDynamicsAX from disk='C:\MOPR\DIT01\MOPRAXR3TST.bak' with replace




if we are getting this below error:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ':'.
Msg 3201, Level 16, State 2, Line 15
Cannot open backup device 'C:\SQL\Backups\$(BackupDevicePath)'. Operating system error 2(The system cannot find the file specified.).
Msg 3013, Level 16, State 1, Line 15

RESTORE DATABASE is terminating abnormally.


we need to write query as:

ALTER DATABASE MicrosoftDynamicsAX SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
RESTORE DATABASE MicrosoftDynamicsAX FROM DISK = 'C:\MicrosoftDynamicsAX_05_26_2015\MicrosoftDynamicsAX_05_26_2015.bak'

GO





No comments:

Post a Comment