PDA

View Full Version : مشکل ارتباط با دیتابیس بعد از عمل Restore



reza1699
پنج شنبه 06 تیر 1392, 09:38 صبح
من از طریق این کد عمل ریستور رو انجام میدم :


string strFileName = string.Empty;
openFileDialog1.Filter = @"SQL Backup files (*.BAK) |*.BAK|All files(*.*) |*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.Title = "Restore SQL File";
openFileDialog1.FileName = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
strFileName = openFileDialog1.FileName;

if (MessageBox.Show("آیا مایل به انجام عمل بازگردانی هستید؟", "بازگردانی", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{

SqlCommand command;
command = new SqlCommand("ALTER DATABASE s1391 SET single_USER WITH ROLLBACK IMMEDIATE", cnn);
command.ExecuteNonQuery();
command = new SqlCommand("use master", cnn);
command.ExecuteNonQuery();
command = new SqlCommand(@"restore database s1391 from disk = '" + strFileName + "' WITH REPLACE", cnn);
command.ExecuteNonQuery();
command = new SqlCommand("ALTER DATABASE s1391 SET multi_USER", cnn);
command.ExecuteNonQuery();
command = new SqlCommand("use s1391", cnn);
command.ExecuteNonQuery();

MessageBox.Show("بازگردانی با موفقیت انجام شد", "بازگردانی", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

}

ولی بعد از انجام عملیات ، با وجود اینکه عمل ریستور به درستی انجام میشه ، ارتباط با پایگاه داده دچار مشکل میشه و این ارور رو دریافت میکنم :

A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)

ولی با یک بار خروج از نرم افزار و ورود مجدد چنین مشکلی دیگه وجود نداره.
چطور میشه کاری کرد که نیاز به خروج از برنامه نباشه؟