hi friends
I used these codes for restoring my DB.But it has error.plz help me.

string backupfile = "D:\\Backup.bak";
            Server svr = new Server(".");
            Database db = new Database(svr, "library");
            Restore rs = new Restore();
            rs.NoRecovery = false;
            rs.Database = "library";
            rs.Action = RestoreActionType.Database;
            BackupDeviceItem bdi = default(BackupDeviceItem);
            bdi = new BackupDeviceItem(backupfile, DeviceType.File);
            rs.Devices.Add(bdi);
            rs.PercentCompleteNotification = 10;
            rs.ReplaceDatabase = true;
      *      rs.SqlRestore(svr);
            db.Refresh();
            db.SetOnline();
            svr.Refresh();

and the ERROR is:
Restore failed for Server 'My computer Name'
And the error is on line *.

Recommended Answers

All 5 Replies

Although your code is C#, your error might be strictly DB. Have you checked the server's error log for more details?

what do u suggest?what should I do?
plz.It's very important.

what do u suggest?what should I do?
plz.It's very important.

You probably need to move this to the Database forum. Check your database error log to see more details of why the process failed. Could be a number of things, including insufficient privileges--like not being adminsitrator. Could be an open connection preventing the task, etc...

Let's think that the problem is Open Connection.
what should I do?
I Closed my connection on Form_Load.Is it true?

Let's think that the problem is Open Connection.
what should I do?
I Closed my connection on Form_Load.Is it true?

Is this a multi-user system, or are you the only user? You don't want to shut down any connections that might be needed.

Also, are you logged in as an administrator? Make sure you are.

If you are the only user and you are certain it is ok to shutdown the DB server, shutting it down and restarting it will ensure there are no hanging connections.

If your restore code still doesn't work after the above, try doing it manually WITHOUT the C# and see if it works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.