如何在c#中使用smo从其他计算机恢复数据库

时间:2015-02-13 02:58:42

标签: c# sql-server-2008

如何使用smo从c#中的其他计算机恢复数据库?这是我的资源:

private void btnrestore_Click(object sender, EventArgs e)
    {
        try
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (srv != null)
            {
                ofd.Title = "Restore BackUp...";
                ofd.Filter = "Backup File|*.bak";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    Restore re_db = new Restore();
                    re_db.Action = RestoreActionType.Database;
                    re_db.Database = cmbDatabase.SelectedItem.ToString();
                    BackupDeviceItem bk_item = new BackupDeviceItem(ofd.FileName, DeviceType.File);
                    re_db.Devices.Add(bk_item);
                    re_db.ReplaceDatabase = true;
                    re_db.SqlRestore(srv);
                }
            }
            else
            {
                MessageBox.Show("A connection to a SQL server was not established.", "Not Connected to Server", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

我希望通过“OpenFileDialog”远程连接到其他计算机。

1 个答案:

答案 0 :(得分:0)

迟到但不会太晚,请查看此页面 http://www.mssqltips.com/tipprint.asp?tip=1849