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
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())
{
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
नमस्ते,
[KaushaL] BlogTwitter [MS MVP 2008 & 2009] [MCC 2011] [MVP Reconnect 2017]
Don't forget to click "Mark as Answer" on the post that helped you
None
0 Points
4 Posts
ASPNETCORE2.0 MYSQL CONNECTION PROBLEM -- please help.
May 17, 2018 09:52 AM|Khanon|LINK
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;
}
}
}
All-Star
31362 Points
7055 Posts
Re: ASPNETCORE2.0 MYSQL CONNECTION PROBLEM -- please help.
May 21, 2018 11:40 AM|kaushalparik27|LINK
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
[KaushaL] Blog Twitter [MS MVP 2008 & 2009] [MCC 2011] [MVP Reconnect 2017]
Don't forget to click "Mark as Answer" on the post that helped you