如何使用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”远程连接到其他计算机。