PDA

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



Collector
دوشنبه 18 مهر 1390, 12:51 عصر
سلام

من وقتی فایل پشتیبان رو بازیابی میکنم و بعدش میخوام از بانک بکاپ بگیرم و یا محتویات یک جدول رو ببینم
این ارور رو میده. مشکل کار کجاست.



A transport-level error has occurred when sending the request to the server. (provider: Named Pipes Provider, error: 0 - No
process is on the other end of the pipe.)




کد بازیابی


string Name = new System.IO.FileInfo(Res1.FileName).Name;
string FF4 = "" + DirectoryName + "";
string yyy = FF4 + "\\" + FileName1;

string E = new System.IO.FileInfo(yyy).Exists.ToString();

if (E == "True")
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\H.mdf;integrated security=true;User Instance=True");
cmd.Connection.Open();
string DBName1 = cmd.Connection.Database;
cmd.Connection.Close();

string query = "ALTER DATABASE [" + DBName1 + "] SET SINGLE_USER WITH ROLLBACK IMMEDIATE ;RESTORE DATABASE [" + DBName1 + "] FROM DISK = '" + yyy + "';ALTER DATABASE [" + DBName1 + "] SET MULTI_USER ;";
cmd.Connection = new SqlConnection(@"Data Source=.\sqlexpress;Integrated Security=True;Connect Timeout=30;User Instance=True");
cmd.Connection.Open();
cmd.CommandText = query;
cmd.ExecuteNonQuery();
cmd.Connection.Close();
}