Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly connect MySQL database with C# application?

I am trying to connect my MySQL database with C# but it's not getting connected.

I am using

static string connstring = @"server=my.live.ip;userid=user;password=123;database=db_name;port=3306";

but still I am getting

Authentication to host 'my.live.ip' for user 'user' using method 'mysql_native_password' failed with message: Access denied for user 'user'@'202.xxx.xxx.xxx' (using password: NO)`

I have searched on it but didn't find any suitable solution(s).

P.S: The live IP that I am using is of azure. i.e. MySQL database is hosted on azure server via xampp

Any help would be highly appreciated

like image 853
Moeez Avatar asked May 30 '20 04:05

Moeez


People also ask

Can we connect MySQL with C?

MySQL databases may be used by programs written in the C programming language on Socrates and Plato and on the IS Solaris workstations. Full details of the C API (Application Program Interface) are given in the MySQL manual.

What is the correct way to connect to a MySQL database?

To connect to the database server, confirm that the MySQL Database Server is running on your machine, right-click the Databases > MySQL Server node in the Services window and choose Connect. You might be prompted to supply a password to connect to the server.

Can I use C# with MySQL database?

Before you start to connect your application to MySql, you need to add add the mysql Reference in your project. To do so, right click our project name, and choose Add Reference, then choose "MySql. Data" from the list. Next, you need to add MySql Library in your C# project.

Does MySQL support C#?

MySql. Data is an implementation of the ADO.NET specification for the MySQL database. It is a driver written in C# language and is available for all . NET languages.


1 Answers

(using password: NO) says that no password was provided. I am not familiar with the connection syntax for C#, but I would suspect that something is wrong with

static string connstring =
     @"server=my.live.ip;userid=user;password=123;database=db_name;port=3306";

Or perhaps connstring is not being used.

Also check the MySQL side. Do SHOW GRANTS FOR 'user'@'202%' or maybe SHOW GRANTS FOR 'user'@'202.xxx.xxx.xxx', depending on whether you used '202%' or '202.xxx.xxx.xxx' as the "host".

You should get back something like

GRANT ... ON dbname.* TO 'user'@'202%' WITH AUTHENTICATION 'mysql_native_password';

Note: having a hostname versus an IP address may be an issue.

like image 69
Rick James Avatar answered Oct 30 '22 23:10

Rick James