我正在尝试使用以下代码从 mysql 本地服务器备份我的数据库:
string folder = DateTime.Now.Date.ToString("yyyy-MM-dd");
var root = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),"Database backup");
var newFolderPath = Path.Combine(root, folder);
if (!Directory.Exists(newFolderPath)) // if it doesn't exist, create
Directory.CreateDirectory(newFolderPath);
MySqlConnection myCon = frmStudentsSignup.establishConnectionToMysql();
using(MySqlCommand cmd = new MySqlCommand()) {
using(MySqlBackup mb = new MySqlBackup(cmd)) {
cmd.Connection = myCon;
myCon.Open();
mb.ExportToFile(newFolderPath);
myCon.Close();
}
}
午餐后这条线
mb.ExportToFile(newFolderPath);
我明白了
access to the path ... is denied.
我的路径位于 Visual Studio 项目目录中。
新目录的创建也正在工作,所以我不知道可能出了什么问题。