Click here to Skip to main content
15,913,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to restore a bak file on(to) remote pc(Sql Server). The file is stored in the remote pc itself. but the code is not working. its not even showing an error.help me please...
{
            //ServerConnection connection = new ServerConnection(server='MRC-9';uid='sa';password='123456';multipleactiveresultsets=false);
            //To Avoid TimeOut Exception
           // Server sqlServer = new Server(connection);
           Restore res = new Restore();

            //this.Cursor = Cursors.WaitCursor;
            //this.dataGridView1.DataSource = string.Empty;

            try
           {
                string fileName = @"\\MRC-9\E\Power_Management.bak";
                string databaseName = "Power_Management";

                res.Database = databaseName;
                res.Action = RestoreActionType.Database;
                res.Devices.AddDevice(fileName, DeviceType.File);

                this.progressBar1.Value = 0;
                this.progressBar1.Maximum = 100;
                this.progressBar1.Value = 10;

                res.PercentCompleteNotification = 10;
                res.ReplaceDatabase = true;
                res.PercentComplete += new PercentCompleteEventHandler(ProgressEventHandler);
                res.SqlRestore(srv);

                MessageBox.Show("Restore of " + databaseName + " Complete!", "Restore", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (SmoException exSMO)
            {
                MessageBox.Show(exSMO.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
              //RestoreDatabase("Power_Management", "sa", "123456", "MRC-9", fileName);
        }
Posted
Updated 25-Mar-13 22:36pm
v3
Comments
CHill60 26-Mar-13 5:07am    
When you step through the code in the debugger does it actually go into the try block?
How has srv been set up?

1 solution

SQL Server 2005 Database Backup and Restore using C# and .NET 2.0[^][]


Read this article this wil help you..
 
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