PDA

View Full Version : مشکل در restore کردن دیتابیس



m@ndana
سه شنبه 04 آذر 1393, 21:26 عصر
سلام

دوستان من یک دیتایس دارم که وقتی به صورت دستی اونو در sql server management اتچ می کنم و توی #c برنامم رو اجرا می کنم restore کار می کنه.

با این command:


"USE [master] RESTORE DATABASE [dbname] FROM DISK = N'" + backupfile + "' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 5"


ولی وقتی دیتابیسم رو از sql server management دیتچ می کنم و توی #c برنامم رو اجرا می کنم restore کار نمی کنه و با این error:




Additional information: The operating system returned the error '5(Access is denied.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'e:\test\test\bin\Debug\dbname.mdf'.


File 'dbname' cannot be restored to 'e:\test\test\bin\Debug\dbname.mdf'. Use WITH MOVE to identify a valid location for the file.


The operating system returned the error '5(Access is denied.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'e:\test\test\bin\Debug\dbname_log.ldf'.


File 'dbname_log' cannot be restored to 'e:\test\test\bin\Debug\dbname_log.ldf'. Use WITH MOVE to identify a valid location for the file.


Problems were identified while planning for the RESTORE statement. Previous messages provide details.


RESTORE DATABASE is terminating abnormally.


Changed database context to 'master'.


دوستان منتظر راهنماییتون هستم

Mahmoud.Afrad
چهارشنبه 05 آذر 1393, 17:05 عصر
کد کامل این قسمت رو بزار

m@ndana
چهارشنبه 05 آذر 1393, 18:39 عصر
سلام

این تابع restore من:






private void Restore(string backupfile )
{
"USE [master] RESTORE DATABASE [myDB] FROM DISK = N'" + backupfile + "' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 5";
this.Cursor = Cursors.WaitCursor;
SqlCommand ocommand = null;
SqlConnection oconnection = null;
SqlConnection.ClearAllPools();
oconnection = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True;User Instance=True");

if (oconnection.State != ConnectionState.Open)
oconnection.Open();

ocommand = new SqlCommand(command, oconnection);
try
{
ocommand.ExecuteNonQuery();
MessageBox.Show("بارگردانی اطلاعات با موفقیت انجام شد");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
this.Cursor = Cursors.Default;
}