PDA

View Full Version : خطا هنگام restore کردن



slashslash2009
پنج شنبه 10 بهمن 1387, 12:00 عصر
سلام
موقعی که دارم از طریق برنامم فایل backup رو restore می کنم یه خطا بهم میده :

Invalid zero-length device name. Reissue the BACKUP statement with a valid device name.
RESTORE DATABASE is terminating abnormally.
Changed database context to 'master'.

از چی می تونه باشه :متفکر:

shamsoft
پنج شنبه 10 بهمن 1387, 12:41 عصر
احتمالا به همون دیتابیسی که می خوای Restore کنی کاننکت شدی. به یه دیتابیس دیگه کانکت بشو (مثلا master) بعد restore کن

slashslash2009
پنج شنبه 10 بهمن 1387, 14:08 عصر
این کد منه کجاشو تغییر بدم . یعنی می کین که inital catalog=master کنم ؟



try
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.;Initial Catalog=anbardari;Integrated Security=True";
SqlCommand cmd = new SqlCommand();
con.Open();
string query = "ALTER DATABASE anbardari SET SINGLE_USER with ROLLBACK IMMEDIATE use master " +
"RESTORE DATABASE anbardari FROM DISK='" + strFileName + "'";
cmd.CommandText = query;
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("بازیابی به درستی انجام شد");
}
catch (Exception ex)
{
MessageBox.Show("Error Occurd :" + ex.Message);
}

shamsoft
پنج شنبه 10 بهمن 1387, 14:41 عصر
بله. فقط connection string رو تغییر بده

slashslash2009
پنج شنبه 10 بهمن 1387, 14:52 عصر
بازم همون خطارو میده :گریه:

shamsoft
پنج شنبه 10 بهمن 1387, 15:31 عصر
چک کن ببین مقدار strFileName قبل از ورود به Query چه مقداری داره. گمونم خالی باشه!

slashslash2009
پنج شنبه 10 بهمن 1387, 18:04 عصر
دوست عزیز حق با شما بود ولی اون مشکلمو حل کردم همش داشتم به این متد فکر می کردم حواسم به جای دیگه نبود ولی یه erore دیگه میده که از طرف sql هم هست : The tail of the log for the database "anbardari" has not been backed up. Use BACKUP LOG WITH NORECOVERY to backup the log if it contains work you do not want to lose. Use the WITH REPLACE or WITH STOPAT clause of the RESTORE statement to just overwrite the contents of the log.
RESTORE DATABASE is terminating abnormally.
Changed database context to 'master'.

کمکم کنید لطفا گناه دارم آخه:متعجب::گریه:

slashslash2009
شنبه 12 بهمن 1387, 12:13 عصر
help me plz?????????????

shamsoft
شنبه 12 بهمن 1387, 21:26 عصر
خط:

"RESTORE DATABASE anbardari FROM DISK='" + strFileName + "'";
رو به خط زیر تغییر بده:

"RESTORE DATABASE anbardari FROM DISK='" + strFileName + "' WITH REPLACE";