Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Restore failed for Server

Author  Topic 

sonalisb
Starting Member

2 Posts

Posted - 2012-08-05 : 06:48:49
I am trying to restore database form .bak file by using code

ServerConnection connection = new ServerConnection(serverName, userName, password);
Server sqlServer = new Server(connection);
Restore rstDatabase = new Restore();
rstDatabase.Action = RestoreActionType.Database;
rstDatabase.Database = databaseName;
string path = "Nilkamaldb.bak";
BackupDeviceItem bkpDevice = new BackupDeviceItem(path, DeviceType.File);
rstDatabase.Devices.Add(bkpDevice);
rstDatabase.ReplaceDatabase = true;
rstDatabase.SqlRestore(sqlServer);



but it gives error Restore failed for Server '[\\.\pipe\8780CEAA-E40B-4F\tsql\query]'
i don't understand why it says??

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2012-08-06 : 05:41:57
quote:
Originally posted by sonalisb

I am trying to restore database form .bak file by using code

ServerConnection connection = new ServerConnection(serverName, userName, password);
Server sqlServer = new Server(connection);
Restore rstDatabase = new Restore();
rstDatabase.Action = RestoreActionType.Database;
rstDatabase.Database = databaseName;
string path = "Nilkamaldb.bak";
BackupDeviceItem bkpDevice = new BackupDeviceItem(path, DeviceType.File);
rstDatabase.Devices.Add(bkpDevice);
rstDatabase.ReplaceDatabase = true;
rstDatabase.SqlRestore(sqlServer);



but it gives error Restore failed for Server '[\\.\pipe\8780CEAA-E40B-4F\tsql\query]'
i don't understand why it says??



Did you try restoring from GUI??
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-06 : 07:00:55
Run it in Visual Studio debugger and look at the variables in the sqlServer object. It may be that the serverName variable has something other than what you expect.

If that does not help, start with the example on this page (which is restoring to a local drive), get that working, change one parameter at a time to match your requirements, testing each step of the way: http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.restore.sqlrestore.aspx
Go to Top of Page

sonalisb
Starting Member

2 Posts

Posted - 2012-08-09 : 01:35:12
yes i tried it on button click event
Go to Top of Page
   

- Advertisement -