مشکل در restore کردن دیتابیس
درود
این کد مربوط به restore کردن منه:
کد:
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\MyDB.mdf;Integrated Security=True;Connect Timeout=45;User Instance=True");
SqlCommand cmd = new SqlCommand();
SqlConnection.ClearAllPools();
string query = "USE [master]; RESTORE DATABASE [MyDB] FROM DISK = N'" + TxtBoxBackupPath.Text + "' WITH NOUNLOAD, REPLACE, STATS = 10";
cmd.Connection = new SqlConnection("Server = .\\SQLEXPRESS ; DataBase = master ; Integrated Security = True");
cmd.Connection.Open();
cmd.CommandText = query;
cmd.ExecuteNonQuery();
cmd.Connection.Close();
هنگام restore کردن ارور زیر رو میده:
کد:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Directory lookup for the file "C:\----\bin\Debug\MyDB.mdf" failed with the operating system error 5(Access is denied.).
File 'MyDB' cannot be restored to 'C:\----\bin\Debug\MyDB.mdf'. Use WITH MOVE to identify a valid location for the file.
Directory lookup for the file "C:\----\bin\Debug\MyDB_log.ldf" failed with the operating system error 5(Access is denied.).
File 'MyDB_log' cannot be restored to 'C:\----\bin\Debug\MyDB_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.
دوستان هر کاری می کنم درست نمیشه. مشکل از کجاست؟