Ivo
Member
- Joined
- Feb 8, 2022
- Messages
- 18
- Programming Experience
- Beginner
Acces denied when try to bakup my database to any place on my harddrive:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace SignalWatch
{
public partial class frmDatabaseBackup : Form
{
SqlConnection con = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=Workflow;Integrated Security=True");
public frmDatabaseBackup()
{
InitializeComponent();
}
private void DatabaseBackup_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
private void btnQuit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnBackupDatabase_Click(object sender, EventArgs e)
{
string database = con.Database.ToString();
if (tbBackupLocation.Text == string.Empty)
{
MessageBox.Show("Please enet Backup Location path");
}
else
{
string cmd = "BACKUP DATABASE[" + database + "] TO DISK= '"+ tbBackupLocation.Text+"\\"+"database"+"_"+DateTime.Now.ToString("dd-MM-yyyy-mm-ss")+".bak'";
con.Open();
SqlCommand command = new SqlCommand(cmd,con);
command.ExecuteNonQuery();
MessageBox.Show("Database backup done successfuly");
con.Close();
btnBackupDatabase.Enabled = false;
}
}
private void btnBrowseBackup_Click(object sender, EventArgs e)
{
FolderBrowserDialog dlg = new FolderBrowserDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
tbBackupLocation.Text = dlg.SelectedPath;
btnBackupDatabase.Enabled = true;
}
}
private void btnBrowseRestore_Click(object sender, EventArgs e)
{
}
}
}