Click here to Skip to main content
16,021,294 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on Database backup and restore.

I have success on local server backup and restore as per user location but when I go for remote server database backup and restore I connect remote sqlserver and get backup then the backup file will be created on remote system not local system then I restore that database it will be restore from remote system back file if I remove that file from remote system then restore. Gives the exception.
C#
Restore sqlRestore = new Restore();
               
BackupDeviceItem deviceItem = new BackupDeviceItem(dataFilePath + "\\" + databaseName + ".bak", DeviceType.File);
               
sqlRestore.Devices.Add(deviceItem);
sqlRestore.Database = databaseName;

ServerConnection connection = new ServerConnection(serverName);
connection.LoginSecure = false;
connection.Login = "gjgjg";
connection.Password = "ytryr";
Server sqlServer = new Server(connection);
                               
sqlRestore.Action = RestoreActionType.Database;
String dataFileLocation = dataFilePath + "\\" + databaseName + ".mdf";
String logFileLocation = dataFilePath + "\\" + databaseName + "_log.ldf";
               
//System.Data.DataTable logicalRestoreFiles = sqlRestore.ReadFileList(sqlServer);
//sqlRestore.RelocateFiles.Add(new RelocateFile(logicalRestoreFiles.Rows[0][0].ToString(),dataFileLocation)); 
//sqlRestore.RelocateFiles.Add(new RelocateFile(logicalRestoreFiles.Rows[1][0].ToString(),logFileLocation));
               
sqlRestore.ReplaceDatabase = false;
//sqlRestore.Complete += new ServerMessageEventHandler(sqlRestore_Complete);
sqlRestore.PercentCompleteNotification = 10;
//sqlRestore.PercentComplete += new PercentCompleteEventHandler(sqlRestore_PercentComplete);
sqlRestore.SqlRestore(sqlServer);

I want to store .bak file on local system and restore from local to remote server

Thank You
Posted
Updated 28-May-11 7:06am
v3
Comments
kailash solanki 28-May-11 9:03am    
if i remove backup file from remote computer then what eillhappen any solution please help me

1 solution

I too have the same problem. Someone can help?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900