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
try abc
1.4k
306
487.2k
Problem restoring database
May 13 2009 8:54 AM
Hello,
I have a database Application and i want to create Backup nad restore Utility in the .Net Application.
for that I am Using the ,
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
backup Process is Working fine but restore cannot work..
Code to restore the database is as Follows
private void btnrestore_Click(object sender, EventArgs e)
{
string result = string.Empty;
try
{
OpenFileDialog ofd = new OpenFileDialog();
if (srv != null)
{
ofd.Title = "Restore BackUp...";
ofd.Filter = "Backup File|*.bak";
if (ofd.ShowDialog() == DialogResult.OK)
{
Restore re_db = new Restore();
re_db.Action = RestoreActionType.Database;
re_db.Database = clsDatabase.DatabaseName;
BackupDeviceItem bk_item = new BackupDeviceItem(ofd.FileName, DeviceType.File);
re_db.Devices.Add(bk_item);
re_db.ReplaceDatabase = true;
re_db.SqlRestore(srv);
MessageBox.Show(this, "The Restore of Database "+clsDatabase.DatabaseName+" Completed Successfully!!.", "Workmate.NET", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
MessageBox.Show("A connection to a SQL server was not established.", "Not Connected to Server", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
catch (FailedOperationException exfa)
{
result = "FailedOperationException error in Backup " + exfa.Message + Environment.NewLine;
result += " Operation : " + exfa.Operation + Environment.NewLine;
result += " TargetSite : " + exfa.TargetSite + Environment.NewLine;
result += " StackTrace : " + exfa.StackTrace + Environment.NewLine;
MessageBox.Show(result);
}
catch (SmoException exsmo)
{
result = "Smo error in Backup " + exsmo.Message + Environment.NewLine;
result += " SmoExceptionType " + Enum.GetName(typeof(SmoExceptionType), exsmo.SmoExceptionType) + Environment.NewLine;
result += " TargetSite : " + exsmo.TargetSite + Environment.NewLine;
result += " StackTrace : " + exsmo.StackTrace + Environment.NewLine;
if (exsmo.InnerException != null)
{
result += " Inner 1 : " + exsmo.InnerException.Message + Environment.NewLine;
}
MessageBox.Show(result);
}
catch (Exception exgen)
{
result = "Generic error in Backup " + exgen.Message + Environment.NewLine;
if (exgen.InnerException != null)
{
result += " Inner 1 : " + exgen.InnerException.Message + Environment.NewLine;
if (exgen.InnerException.InnerException != null)
{
result += " Inner 2 : " + exgen.InnerException.InnerException.Message + Environment.NewLine;
}
// i needed only one time to go further in the innerexception in 4 years
MessageBox.Show(result);
}
}
}
when i run this code it gives an error saying 'FailedOperationException error in Backup Restore failed for Server'
can anybody have any idea !!!
Reply
Answers (
0
)
Working with Bits
compare two dataset without using loop