Необработанное исключение, MySql .Data.MySqlClient.MySqlException - PullRequest
0 голосов
/ 26 мая 2020

После того, как я написал код в своей Visual Studio Pro, на панели списков ошибок нет ошибок. Поэтому, когда я запустил код, появилось окно исключения Unhandled, как показано ниже:

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)

Тогда я не могу найти что-либо для исследования повсюду в Google. Итак, проблема в том, что я даже не могу знать, что случилось с моим кодом. Поэтому, пожалуйста, объясните мне немного и дайте какое-то решение. И когда я нажимаю на просмотр деталей, там много информации. Так что, полагаю, этого недостаточно.

И я просто нажал на детали копии. Итак, вот код ниже:

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)

Итак, вот код моей Visual Studio Pro ниже:

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)
        {

        }
    }
}

1 Ответ

0 голосов
/ 28 мая 2020

Судя по моему тесту, проблема может быть связана с вашей строкой подключения.

Я предлагаю добавить ';' после "database = superops" и проверьте правильность пароля.

...