public void VeritabaniBackUpAl() {
string sSource;
string sLog;
string sEvent;
sSource = "DBBackup";
sLog = "Application";
sEvent = "BackUpBasladi";
string sSource;
string sLog;
string sEvent;
sSource = "DBBackup";
sLog = "Application";
sEvent = "BackUpBasladi";
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
EventLog.CreateEventSource(sSource, sLog);
EventLog.WriteEntry(sSource, sEvent);
EventLog.WriteEntry(sSource, sEvent,
EventLogEntryType.Warning, 234);
EventLog.WriteEntry(sSource, sEvent,
EventLogEntryType.Warning, 234);
string conString = "Data Source=localhost; Initial Catalog=DatabaseName;" +
" User ID=UserNAme; Password=Pass;";
string command = "BACKUP DATABASE DatabaseName TO DISK = 'E:\\Yedek\\Yedek-" +
DateTime.Now.ToShortDateString() + "-" + DateTime.Now.Ticks.ToString() + ".bak'";
SqlConnection con = new SqlConnection(conString);
" User ID=UserNAme; Password=Pass;";
string command = "BACKUP DATABASE DatabaseName TO DISK = 'E:\\Yedek\\Yedek-" +
DateTime.Now.ToShortDateString() + "-" + DateTime.Now.Ticks.ToString() + ".bak'";
SqlConnection con = new SqlConnection(conString);
SqlCommand myCommand = new SqlCommand(command, con);
try
{
EventLog.WriteEntry(sSource, "Connection Açılıyor");
{
EventLog.WriteEntry(sSource, "Connection Açılıyor");
con.Open();
EventLog.WriteEntry(sSource, "Komut Çalıştırılıyor");
myCommand.ExecuteNonQuery();
// MessageBox.Show("Yedekleme işlemi tamamlandı.", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Information);
EventLog.WriteEntry(sSource, "BackupBitti");
}
catch (Exception e)
{
EventLog.WriteEntry(sSource, "BackUpHataOluştu"+e.Message,EventLogEntryType.Error);
//MessageBox.Show(err.Message, "Hata");
{
EventLog.WriteEntry(sSource, "BackUpHataOluştu"+e.Message,EventLogEntryType.Error);
//MessageBox.Show(err.Message, "Hata");
}
finally
{
EventLog.WriteEntry(sSource, "Connection Kapatılıyor");
con.Close();
}
}
finally
{
EventLog.WriteEntry(sSource, "Connection Kapatılıyor");
con.Close();
}
}
Hiç yorum yok:
Yorum Gönder