PDA

View Full Version : سوال: بک آپ گیری اتوماتیک از SQL



NasimBamdad
دوشنبه 28 فروردین 1391, 22:05 عصر
سلام .

من از کد زیر برای BackUP گرفتم از DB استفاده می کنم .


progressBarX1.Visible = true;
//////////////
string datez = todayShamsi().ToShortDateString();
string[] str = datez.Split('/');
for (int i = 0; i < str.Length; i++) ;
string day = str[0];
string month = str[1];
string year = str[2];
/////////////
TimeSpan z = DateTime.Now.TimeOfDay;
string mm = Convert.ToString(z);
string hour = mm.Substring(0, 2);
string minute = mm.Substring(3, 2);
////////////

SqlConnection cnn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
SqlCommand cmd = new SqlCommand();
cmd.Connection = cnn;
cnn.Open();
cmd.CommandText = "BACKUP DATABASE NoorAutomation TO DISK = @Destination";
cmd.Parameters.AddWithValue("@Destination", Application.StartupPath + "\\DB_BackUP\\BackUP-" + year + "-" + month + "-" + day + "_" + hour + "-" + minute + ".Bak");
cmd.ExecuteNonQuery();
cnn.Close();

MessageBox.Show("از دیتابیس بک آپ گرفته شد");

progressBarX1.Visible = false;
string[] dirs = Directory.GetFiles(Application.StartupPath + "\\DB_BackUP");
listBox1.Items.Clear();
listBox1.Items.AddRange(dirs);


حالا می خواهم این کد رو در فواصل زمانی ، مثلا 10 دقیقه یکبار اجرا کنم ، بدون اینکه کاربر متوجه بشود و یا اخلالی در کارش ایجاد کنم .

نمی دونم از Thread باید استفاده کنم ، از Parallel و . یا ................

ممنون می شم کمکم کنید .