I'm trying to restore the database to SQL Server.
At first I got this error:
Directory lookup for the file "C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\myDataBase.mdf" failed with the operating system error 3(System can't find path).
File 'myDataBase' cannot be restored to 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\myDataBase.mdf'. Use WITH MOVE to identify a valid location for the file.
Directory lookup for the file "C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\myDataBase_log.ldf" failed with the operating system error 3(System can't find path).
File 'myDataBase' cannot be restored to 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\myDataBase_log.ldf'. Use WITH MOVE to identify a valid location for the file.
Problems were identified while planning for the RESTORE statement. Previous messages provide details.
RESTORE DATABASE is terminating abnormally.
The problem is that my server is not running SQL Server Express. I have no idea where that part of the path comes from.
After I've created the folder, because It didn't exist on my pc, the error I got:
The operating system returned the error '5(Access is denied.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\myDataBase.mdf'. File 'myDataBase' cannot be restored to 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\myDataBase.mdf'. Use WITH MOVE to identify a valid location for the file. The operating system returned the error '5(Acccess is denied)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\myDataBase_log.ldf'. File 'myDataBase_log' cannot be restored to 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\myDataBase_log.ldf'. Use WITH MOVE to identify a valid location for the file. Problems were identified while planning for the RESTORE statement. Previous messages provide details. RESTORE DATABASE is terminating abnormally
I've tried to run Visual as admin and SQL Server as well.
Restoring databases from SQL Server works fine.
Here is my code:
public RestoredDB RestoreDB(string destPath, string dbName)
{
var myServer = new Server(@"LOCALHOST");
var restoredDb = new RestoredDB();
var res = new Restore();
res.Database = dbName;
res.Action = RestoreActionType.Database;
res.Devices.AddDevice(destPath, DeviceType.File);
res.PercentCompleteNotification = 10;
res.ReplaceDatabase = true;
try
{
res.SqlRestore(myServer);
restoredDb.Name = dbName;
restoredDb.isRestored = true;
return restoredDb;
}
catch(Exception e)
{
MessageBox.Show(dbName + " couldn't be restored");
restoredDb.Name = dbName;
restoredDb.isRestored = false;
return restoredDb;
}
}
It probably has something to do with permissions? How do I change them?
Edit: Is there any way to change the directory in the first error msg? Some myServer property or something? I can't find it anywhere