locked
ASPNETCORE2.0 MYSQL CONNECTION PROBLEM -- please help. RRS feed

  • Question

  • User1881255788 posted

    Hello.. I'm working on an ASP net core 2.0 mvc 5 Project and I'm having problems on trying to connect to an online mysql database.

    I Will share all the information I get from the website that provides free database hosting service, becouse they r not precious anyways, and just for testing...

    I will be really thankfull if someone could help me... I'm running out of time and I'm yet to start the project.

    Thank you already.

    ------------------------------------

    Your account number is: 288396

    Your new database is now ready to use.

    To connect to your database use these details

    Server: sql7.freemysqlhosting.net
    Name: sql7238434
    Username: sql7238434
    Password: 4qjcgJuxxU
    Port number: 3306

    appsettings.json

    "ConnectionStrings": {

    "DefaultConnection": "server=sql7.freemysqlhosting.net;port=3306;database=sql7238434;uid=sql7238434;password=4qjcgJuxxU"
    },
    "Logging": {
    "IncludeScopes": false,
    "LogLevel": { "Default": "Warning" }
    }
    }

    CONTEXT.CS

    public class HerseyinContext
    {
    public string ConnectionString { get; set; }
    public HerseyinContext(string connetionString)
    {
    this.ConnectionString = ConnectionString;

    }
    private MySqlConnection GetConnection()
    {
    return new MySqlConnection(ConnectionString);
    }


    public List<Users> GetAllUsers()
    {
    List<Users> list = new List<Users>();
    using (MySqlConnection conn = GetConnection())
    {
    conn.Open(); ---------HERE I GET THE ERORR! -->MySql.Data.MySqlClient.MySqlException: 'Host 'ASUS' is not allowed to connect to this MariaDB server'
    MySqlCommand cmd = new MySqlCommand("select * from Users", conn);
    using (var reader = cmd.ExecuteReader())
    {
    while (reader.Read())
    {

    list.Add(new Users()
    {
    ID = Convert.ToInt32(reader["ID"]),
    USERNAME = reader["USERNAME"].ToString(),
    PASSWORD = reader["PASSSWORD"].ToString()
    });


    }
    }
    return list;
    }
    }


    }

    Thursday, May 17, 2018 9:52 AM

All replies

  • User-1509636757 posted

    conn.Open(); ---------HERE I GET THE ERORR! -->MySql.Data.MySqlClient.MySqlException: 'Host 'ASUS' is not allowed to connect to this MariaDB server'

    It can simply be a security precaution or privileges issue in My SQL. However, MariaDB is a fork of MySQL, so I am not sure if this is the same case with MariaDB as well. Try adding a new Administrative account. Here is a thread that shows how you do that via sql commands: Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server

    Monday, May 21, 2018 11:40 AM