Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Restoring databases (http://www.go4expert.com/forums/restoring-databases-t10080/)

im1dermike 16Apr2008 23:07

Restoring databases
 
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?


All times are GMT +5.5. The time now is 14:22.