Exception Unhandled, MySql.Data.MySqlClient.MySqlException

0

After I've done code on my visual studio pro there is no errors on error lists bar. So when I ran the code the exception Unhandled window popped up like code below:

MySql.Data.MySqlClient.MySqlException
  HResult=0x80004005
  Message=Authentication to host 'localhost' for user '' using method 'mysql_native_password' failed with message: Access denied for user ''@'localhost' (using password: NO)

Inner Exception 1:
MySqlException: Access denied for user ''@'localhost' (using password: NO)

Then I can't find anything for research everywhere on google. So the problem is I can't even know what's happened to my code. So please explain to me a little bit and give me some sort of solution. And when I click on view the details there is a lot of info there. So I suppose that's can't give enough explanation.

And I just clicked on the copy details. So here is the code below:

MySql.Data.MySqlClient.MySqlException
  HResult=0x80004005
  Message=Authentication to host 'localhost' for user '' using method 'mysql_native_password' failed with message: Access denied for user ''@'localhost' (using password: NO)
  Source=MySql.Data
  StackTrace:
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex)
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset)
   at MySql.Data.MySqlClient.NativeDriver.Authenticate(String authMethod, Boolean reset)
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at superpos3.itemss.pictureBox1_Click(Object sender, EventArgs e) in D:\superpos3\superpos3\superpos3\itemss.cs:line 50
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at superpos3.Program.Main() in D:\superpos3\superpos3\superpos3\Program.cs:line 19

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
MySqlException: Access denied for user ''@'localhost' (using password: NO)

So here is the code on my visual studio pro below:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace superpos3
{
    public partial class itemss : Form
    {
        public itemss()
        {
            InitializeComponent();
        }
        MySqlConnection con = new MySqlConnection("server= localhost; database =superpos username= root; password=; ");
        private object txtname;

        private void itemss_Load(object sender, EventArgs e)
        {

        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void tabPage1_Click_1(object sender, EventArgs e)
        {

        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            MySqlCommand cmd = new MySqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "insert into category(name,Description)values(@name,@Description)";
            cmd.Parameters.AddWithValue("@name", txtna.Text);
            cmd.Parameters.AddWithValue("@Description", txtdes.Text);

            con.Open();
            cmd.ExecuteNonQuery();
            MessageBox.Show("Record added ..............");
            con.Close();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
c#
.net
visual-studio
error-handling
asked on Stack Overflow May 26, 2020 by Bilguun Enkhee

1 Answer

0

Based on my test, the problem may be related to your connection string.

I suggest that add ';' after the "database = superops" and check if your password is correct.

answered on Stack Overflow May 28, 2020 by Jack J Jun - MSFT

User contributions licensed under CC BY-SA 3.0