Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone, i'm building an application, it can backup and restore database from sql server, but it doesn't work when i remote to other computer.
I want to built an application to remote other computer by 'conectionsString" to restore database from other machine such as "Locate Backup File" form in SMO

This code restore database from my computer, it doesn't when remote to other computer
C#
private void btnRestore_Click(object sender, EventArgs e)
       {
           if (srvSql != null)
           {
               if (openBackupDialog.ShowDialog() == DialogResult.OK)
               {
                   Restore rstDatabase = new Restore();
                   rstDatabase.Action = RestoreActionType.Database;
                   rstDatabase.Database = cmbDatabase.SelectedItem.ToString();
                   BackupDeviceItem bkpDevice = new
                   BackupDeviceItem(openBackupDialog.FileName, DeviceType.File);
                   rstDatabase.Devices.Add(bkpDevice);
                   rstDatabase.ReplaceDatabase = true;
                   rstDatabase.SqlRestore(srvSql);
               }
           }
           else
           {
               MessageBox.Show("A connection to a SQL server was not established.", "Not Connected to Server", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
           }
Posted

1 solution

Start by checking which instance of SQL server you are accessing when you do the restore: it has to be the remote version, not your local instance. Check your connection string carefully, and make sure that your user on the remote server has the correct permissions needed to create databases (which is what a restore operation involves, after all).
 
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