---
title: "I want to restore a database .bak file(Tasks->Restore->Database; after I select from device and select file"  
description: "I want to restore a database .bak file(Tasks->Restore->Database; after I select from device and select file"  
author: "Santosh Kumar Singh"  
published: 2014-12-18  
updated: 2014-12-19  
canonical: https://www.mindstick.com/forum/12789/i-want-to-restore-a-database-bak-file-tasks-restore-database-after-i-select-from-device-and-select-file  
category: "database"  
tags: ["sql server 2012"]  
reading_time: 1 minute  

---

# I want to restore a database .bak file(Tasks->Restore->Database; after I select from device and select file

The [operating system](https://www.mindstick.com/articles/229069/operating-system-development) returned the error '5([Access is denied](https://www.mindstick.com/forum/33446/sql-server-restore-error-access-is-denied).)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'E:\[Program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) Files\[Microsoft SQL](https://www.mindstick.com/forum/159597/my-sql-server-vs-microsoft-sql-server-which-one-better) [Server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over)\MSSQL10.MSSQLSERVER\MSSQL\DATA\XXXXXX.mdf'. Msg 3156, Level 16, State 8, Server XXXX, Line 2 [Friends](https://answers.mindstick.com/qa/31396/where-did-the-suggest-to-friends-feature-go) you have solution, please share with me. Thanks.

## Replies

### Reply by Anonymous User

You could use something like the following script. It restores a database from the filesystem, and it overwrites the existing database with the name of "MyDB", moving the files to new locations of your choice in the process.

RESTORE DATABASE

MyDB

FROM DISK = '\\MyShare\MyBackup.bak'

WITH

MOVE 'DataFile' TO 'D:\myNewDBLocation\DataFile.mdf',

MOVE 'LogFile' TO 'E:\\myNewDBLocation\LogFile.ldf'

, REPLACE

You can find out the name of the llogical files (in the above, those are called DataFile and LogFileby running the following:

RESTORE FILELISTONLY

FROM DISK = '\\MyShare\MyBackup.bak'

Additional information about various options and parameters:


---

Original Source: https://www.mindstick.com/forum/12789/i-want-to-restore-a-database-bak-file-tasks-restore-database-after-i-select-from-device-and-select-file

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
