简体   繁体   English

对路径“”“”的访问被拒绝 C#

[英]access to the path “”“”" is denied C#

I'm logged in as an admin on my PC, but this shows up我在我的 PC 上以管理员身份登录,但这显示

here's my code:这是我的代码:

string file = "C:\\Users\\owner\\Documents\\backup.sql";
using (MySqlConnection conn = new MySqlConnection(constring))
{
    using (MySqlCommand cmd = new MySqlCommand())
    {
        using (MySqlBackup mb = new MySqlBackup(cmd))
        {
            try
            {
                cmd.Connection = conn;
                conn.Open();
                mb.ExportToFile(file);
                conn.Close();
            }catch(Exception ex){
                MessageBox.Show(ex.Message);
            }
        }
    }
}

PS: I already have a connection string at the very top of my code. PS:我的代码最顶部已经有一个连接字符串。

There is a possibility, that you are getting the error because the file doesn't exist.有可能您收到错误,因为该文件不存在。 I could be wrong, but I looked into the source and it doesn't check whether the file already exists.我可能是错的,但我查看了源代码,它没有检查文件是否已经存在。

hey ?嘿 ? are you using mysqlbackup.dll as reference ?您是否使用 mysqlbackup.dll 作为参考? if yes maybe this can help .. just go to the folder you want to be the storage of your saved files如果是的话,这可能会有所帮助..只需转到您想要存储已保存文件的文件夹

Private Sub BackupDatabaseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackupDatabaseToolStripMenuItem.Click

  'using mysqlbackup.dll as reference

  Dim cmd As MySqlCommand = New MySqlCommand

  cmd.Connection = connect()

  Dim filepth As String = "C:\Users\IT\Documents\DB_Backup.sql"

  Dim mb As MySqlBackup = New MySqlBackup(cmd)

  mb.ExportToFile(filepth)

  MsgBox("Database Backup Successfully !", MsgBoxStyle.Information, "Project")

  disconnect()
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM