1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Restoring databases

Discussion in 'C#' started by im1dermike, Apr 16, 2008.

  1. im1dermike

    im1dermike New Member

    Joined:
    Apr 16, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi. I'm new to C#, but have a project I'm working on. I need to restore a database. Here is the code I have so far:

    Server svr = new Server();
    Restore res = new Restore();
    res.Database = "CAPS";
    res.Action = RestoreActionType.Database;
    res.Devices.AddDevice(BACKUPFILE, DeviceType.File);
    res.ReplaceDatabase = true;
    res.SqlRestore(svr);

    The issue is that the *.mdf and *.ldf log files are set in the *.BAK file to be saved in mapped drives that don't exist. I think I need to be able to set the file location for these files like I can when I script it in SQL:

    RESTORE DATABASE [CAPS]
    FROM DISK = N'C:\CAPS_BACKUP\CAPS_db_200804132010.BAK'
    WITH FILE = 1, MOVE N'CAPS' TO N'C:\CAPS_BACKUP\Data\CAPS.mdf',
    MOVE N'CAPS_log' TO N'C:\CAPS_BACKUP\Data\CAPS_log.LDF', NOUNLOAD, STATS = 10
    GO

    Help?
     

Share This Page