不要恢复我的备份文件请帮助 [英] Do not Restore my Back up file Please Help

查看:63
本文介绍了不要恢复我的备份文件请帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 Cursor.Current = Cursors.WaitCursor; 

尝试
{
if (txtFileName。 Text ==
{
MessageBox.Show( 请选择还原文件。,Application.ProductName,MessageBoxButtons.OK,MessageBoxIcon.Information);
txtFileName.Focus();
return ;
}
FileInfo file = new FileInfo(txtFileName.Text);
if (file.Exists)
{
if (MessageBox .Show( 你确定要恢复吗? 返回,MessageBoxButtons.YesNo,MessageBoxIcon.Question)== DialogResult.Yes)
{
if (file.Extension == .mbk
{



}

其他

{



FileInfo filebak = new FileInfo(txtFileName.Text);



String Conn = File.ReadAllText(ConnectionString.txt);

SqlConnection _SqlConnection = new SqlConnection(Conn );

_SqlConnection.Open();

// _ SqlCommand = new SqlCommand(use master,connect);

// _ SqlCommand .ExecuteNonQuery();

_SqlCommand = new SqlCommand(USE master ALTER DATABASE+PragatiDB+SET SINGLE_USER WITH ROLLBACK IMMEDIATE; ALTER DATABASE+PragatiDB+SET MULTI_USER;,_ SqlConnection);

_SqlCommand.ExecuteNonQuery();

_SqlCommand = new SqlCommand(@restore database+ PragatiDB+from disk ='+ BackupPath_bak +\\+ filebak.Name +'WITH REPLACE,_ SSConnection);

_SqlCommand.ExecuteNonQuery();

_SqlConnection.Close();

//Directory.Delete(BackupPath_bak,true);





}

MessageBox.Show(数据库+PragatiDB+恢复成功。,恢复,MessageBoxButtons.OK,MessageBoxIcon.Information);

}

}

其他

MessageBox.Show(@不要在上面做任何认可(或者不在更正中) t path),Restoration,MessageBoxButtons.OK,MessageBoxIcon.Information);



}

catch(Exception exp)

{

MessageBox.Show(exp.Message,Application.ProductName,MessageBoxButtons.OK,MessageBoxIcon.Error);

}



}

解决方案

试试这个:

  string  filename = '  D:\BK \'+ db_name + ' .bak '  
_SqlCommand = new SqlCommand(@restore database+PragatiDB +from disk ='
+ filename + ' WITH REPLACE,_ SqlConnection);


Cursor.Current = Cursors.WaitCursor;

           try
           {
               if (txtFileName.Text == "")
               {
                   MessageBox.Show("Please Select Restore File.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                   txtFileName.Focus();
                   return;
               }
               FileInfo file = new FileInfo(txtFileName.Text);
               if (file.Exists)
               {
                   if (MessageBox.Show("Are you sure you restore?", "Back", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                   {
                       if (file.Extension == ".mbk")
                       {


}
else
{

FileInfo filebak = new FileInfo(txtFileName.Text);

String Conn = File.ReadAllText("ConnectionString.txt");
SqlConnection _SqlConnection = new SqlConnection(Conn);
_SqlConnection.Open();
//_SqlCommand = new SqlCommand("use master", connect);
//_SqlCommand.ExecuteNonQuery();
_SqlCommand = new SqlCommand("USE master ALTER DATABASE " + "PragatiDB" + " SET SINGLE_USER WITH ROLLBACK IMMEDIATE; ALTER DATABASE " + "PragatiDB" + " SET MULTI_USER;", _SqlConnection);
_SqlCommand.ExecuteNonQuery();
_SqlCommand = new SqlCommand(@"restore database " + "PragatiDB" + " from disk = '" + BackupPath_bak + "\\" + filebak.Name + "' WITH REPLACE", _SqlConnection);
_SqlCommand.ExecuteNonQuery();
_SqlConnection.Close();
//Directory.Delete(BackupPath_bak, true);


}
MessageBox.Show("Database " + "PragatiDB" + " Restored successfully.", "Restoration", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
MessageBox.Show(@"Do not make any endorsement above (or is not in the correct path)", "Restoration", MessageBoxButtons.OK, MessageBoxIcon.Information);

}
catch (Exception exp)
{
MessageBox.Show(exp.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}

解决方案

try this:

string filename='D:\BK\'+db_name+'.bak'
_SqlCommand = new SqlCommand(@"restore database " + "PragatiDB" + " from disk = "'+filename+'" WITH REPLACE", _SqlConnection);


这篇关于不要恢复我的备份文件请帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆