SQL DATABASE BACKUP ALAN KOD BLOĞU
using System.Data;
using System.Data.SqlClient;
//-------
//namespace alanları
SqlConnection con;
SqlCommand cmd;
string conString = "";
SqlDataAdapter da;
DataTable dt;
string cmdText = "";
private void btnBackUp_Click(object sender, EventArgs e)
{
try
{
if (cmbDatabases.SelectedItem == null || txtLocation.Text.Trim()=="")
{
MessageBox.Show("Lütfen bir veritabanı ya da kayıt yeri seçin!");
return;
}
conString = "Server=" + txtServerName.Text + "; Database= EBA; Integrated Security=True;";
con = new SqlConnection(conString);
con.Open();
cmdText = String.Format("BACKUP DATABASE {0} TO DISK='{1}'",
cmbDatabases.Text, txtLocation.Text + "\\"+cmbDatabases.Text + " - " + DateTime.Now.ToShortDateString() +".BAK");
cmd = new SqlCommand(cmdText, con);
cmd.ExecuteNonQuery();
MessageBox.Show("Backup was completed succesfully");
cmd.Dispose();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Hiç yorum yok:
Yorum Gönder