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
leathu raj
NA
62
79.4k
Restore database through c# codings
Oct 6 2014 8:16 AM
Hai,
I want to restore database backup file(.bak) to sql server 2012 from my c# program. Restored database name is from textbox text.
I used the following coding. It works on local connection only. when i used the same coding on my sql server connected with name like XXXX\SQL EXPRESS i got error restored failed for server 'XXXX\SQL EXPRESS'.
Please help me.... Thanks in advance....
ServerConnection srvConn = new ServerConnection(@"XXXXX\\SQLEXPRESS");
instead of this line i use
ServerConnection srvConn = new ServerConnection("localhost");
this line work on loacl connection.
try
{
private static Server srvr;
ServerConnection srvConn = new ServerConnection(@"WIN-6A67QTTNU6J\\SQLEXPRESS");
srvConn.LoginSecure = true;
srvr = new Server(srvConn);
Restore rstDatabase = new Restore();
rstDatabase.Action = RestoreActionType.Database;
string name = txt_cmpnyname.Text;
rstDatabase.Database = name;
BackupDeviceItem bkpDevice = new BackupDeviceItem("E:\\shop", DeviceType.File);
rstDatabase.Devices.Add(bkpDevice);
rstDatabase.ReplaceDatabase = true;
rstDatabase.SqlRestore(server);
MessageBox.Show("Restored Successfully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Reply
Answers (
3
)
Waiting for answers.
Beginner help