جوان ایرانی
جمعه 11 فروردین 1391, 02:17 صبح
سلام دوستان
من برای ریستور از این کد استفاده کردم ولی اکسپشن داره چکار کنم لطفا راهنمایی ام کنید خواهش میکنم
private void Restore(string strFileName)
{
try
{
string command = @"ALTER DATABASE QABank SET SINGLE_USER with ROLLBACK IMMEDIATE " +
"use master " +
" RESTORE DATABASE QuestionAnswerBank FROM DISK='" + strFileName + "'";
this.Cursor = Cursors.WaitCursor;
SqlCommand Command = null;
SqlConnection Connection = null;
Connection = new SqlConnection("Data Source=localhost;Initial Catalog=QuestionAnswerBank;Integrated Security=True");
if (Connection.State != ConnectionState.Open)
Connection.Open();
Command = new SqlCommand(command, Connection);
Command.ExecuteNonQuery();
this.Cursor = Cursors.Default;
MessageBox.Show("بازیابی با موفقیت انجام شد");
}
catch (Exception ex)
{
MessageBox.Show("Error Occurd :" + ex.Message);
}
}
private void button15_Click(object sender, EventArgs e) ////کلید بازیابی
{
string strFileName = string.Empty;
openFileDialog1.Filter = @"SQL Backup files (*.bak) |*.bak|All files (*.*) |*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.Title = "Restore SQL File";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
strFileName = saveFileDialog1.FileName;
Restore(strFileName);
}
}
اکسپشن:
Invalid zero-length device name. Reissue the BACKUP statement with a valid device name.
RESTORE DATABASE is terminating abnormally.
Changed database context to 'master'.
من برای ریستور از این کد استفاده کردم ولی اکسپشن داره چکار کنم لطفا راهنمایی ام کنید خواهش میکنم
private void Restore(string strFileName)
{
try
{
string command = @"ALTER DATABASE QABank SET SINGLE_USER with ROLLBACK IMMEDIATE " +
"use master " +
" RESTORE DATABASE QuestionAnswerBank FROM DISK='" + strFileName + "'";
this.Cursor = Cursors.WaitCursor;
SqlCommand Command = null;
SqlConnection Connection = null;
Connection = new SqlConnection("Data Source=localhost;Initial Catalog=QuestionAnswerBank;Integrated Security=True");
if (Connection.State != ConnectionState.Open)
Connection.Open();
Command = new SqlCommand(command, Connection);
Command.ExecuteNonQuery();
this.Cursor = Cursors.Default;
MessageBox.Show("بازیابی با موفقیت انجام شد");
}
catch (Exception ex)
{
MessageBox.Show("Error Occurd :" + ex.Message);
}
}
private void button15_Click(object sender, EventArgs e) ////کلید بازیابی
{
string strFileName = string.Empty;
openFileDialog1.Filter = @"SQL Backup files (*.bak) |*.bak|All files (*.*) |*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.Title = "Restore SQL File";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
strFileName = saveFileDialog1.FileName;
Restore(strFileName);
}
}
اکسپشن:
Invalid zero-length device name. Reissue the BACKUP statement with a valid device name.
RESTORE DATABASE is terminating abnormally.
Changed database context to 'master'.