Search code examples
mysql.net-coreraspberry-pi3raspbianubuntu-18.04

How to execute a program with access to mysql outside of published folder?


I have a .net core console application that accesses MySQL. I have compiled the application to run successfully on my raspberry pi, which also hosts the MySQL database. After I sftp my compiled code to my raspberry pi, I can successfully run the code if I am inside of the folder that contains the application. However, if I go up a level and try to run the app. I get an authentication error from MySQL. For example, inside of my publish folder, I can run ./Application without any issues. If I go up a level and then run, for example, publish/Application, it fails with the authentication error.

Below is the exception I am getting.

Unhandled Exception: MySql.Data.MySqlClient.MySqlException: Authentication to host '' for user '' using method 'mysql_native_password' failed with message: Access denied for user ''@'localhost' (using password: NO) ---> MySql.Data.MySqlClient.MySqlException: Access denied for user ''@'localhost' (using password: NO)

Also below you can see my app settings file that has my connection information.

{
  "ConnectionStrings": {
    "TestDB": "Server=127.0.0.1;Database=TestDB;Uid=remote;Pwd=remote"
  }
}

Here is also the query I used to grant my user access to the DB.

GRANT ALL PRIVILEGES ON TestDB.* TO remote@'%' IDENTIFIED BY 'remote';

Does anyone know what could be causing this issue? My end goal is to be able to execute the application from any directory in order to add it to the cron daemon.

Any help would be appreciated.

Thank you.


Solution

  • I think, you have error in connection string.

    Try this:

    {
      "ConnectionStrings": {
        "TestDB": "Server=127.0.0.1;Database=TestDB;User=remote;Password=remote"
      }
    }
    

    I just replaced Uid and Pwd with User and Password