65.9K
CodeProject 正在变化。 阅读更多。
Home

SQL 数据库还原

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.33/5 (3投票s)

2009 年 4 月 1 日

CPOL
viewsIcon

22425

downloadIcon

1135

带有 MEDIAPASSWORD 数据库的备份 T-SQL 字符串生成器。

引言

此应用程序是用于创建数据库还原操作 T-SQL 脚本的第三方工具。

您可以使用 SQL Server Management Studio GUI 还原数据库,但无法还原带有 MEDIAPASSWORD 保护的备份文件! 在这种情况下,您必须编写 SQL 字符串,但这非常枯燥。

此工具让您可以快速生成 SQL 字符串,并且可以生成差异还原字符串。 此应用程序将您的连接信息存储在 XML 文件中。

使用代码

这段代码显示备份文件的附加信息

private void btnSelectDiffFile_Click(object sender, EventArgs e)
{
    try
    {
        isConnected();

        if (_isConnected & server != null & !string.IsNullOrEmpty(_remoteUser) 
                         & !string.IsNullOrEmpty(_remotePass))
        {
            string cUser = _remoteUser != null ? _remoteUser : string.Empty;
            string cPass = _remotePass != null ? _remotePass : string.Empty;

            FileSelectDialog fileselect = new FileSelectDialog();
            DialogResult result = fileselect.ShowDialog(server,cUser,cPass);
            if (result == DialogResult.OK)
            {                        

                string backtoLocalName = fileselect.Show();
                backtoLocalName = backtoLocalName.Replace("$", ":");
                backtoLocalName = backtoLocalName.Replace(_serverName != null ? 
                                  _serverName : string.Empty, string.Empty);
                backtoLocalName = backtoLocalName.Replace("\\\\\\", string.Empty);
                txtDiffFile.Text = backtoLocalName;
                
                Restore res = new Restore();
                res.Devices.AddDevice(backtoLocalName, DeviceType.File);

                DataTable dt = res.ReadBackupHeader( server );

                CreateTextBoxColumn( grdDiffBackups, "BackupName", "BackupName" );
                CreateTextBoxColumn( grdDiffBackups, "Position", "Position" );
                CreateTextBoxColumn( grdDiffBackups, "BackupStartDate", 
                                     "BackupStartDate" );
                grdDiffBackups.AutoGenerateColumns = false;
                
                bsDiff.DataSource = dt;
                
                grdDiffBackups.DataSource = bsDiff;
            }
        }
        else
        {
            MessageBox.Show("Username/Password is null or empty!");
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
© . All rights reserved.