TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mike
NA
9
0
Restoring databases
Apr 16 2008 1:38 PM
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?
Reply
Answers (
0
)
read write lock in C#
How to make a databind from a DataSet With Data Tables and TablesAdapters