1

I tried to use this code to login to my vb.net application using mysql. But I have this error

An unhandled exception of type 'System.Security.Authentication.AuthenticationException' occurred in MySql.Data.dll. Additional information: Échec d'un appel à SSPI, consultez l'exception interne. I have this error only with windows 10, there are no problems with Windows 7

I read here a solution.

I tried to add this line

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;" before 

Dim Str As String = "SERVER=localhost; 
    uid =root;
DATABASE =mag;
PASSWORD =;"" 

but it didn't work.

Imports MySql.Data.MySqlClient
Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim Str As String = "SERVER=localhost; uid =root;DATABASE =mag;PASSWORD =;"
        Dim cc As New MySqlConnection(Str)
        Try
            conn.Open()
            Dim Sql = "SELECT *  FROM tab1 WHERE  login='" & TextBox1.Text & "' and password='" & TextBox2.Text & " '"
            Dim cmd = New MySqlCommand(Sql, cc)
            Dim dr = cmd.ExecuteReader
            dr.Read()
            If dr.HasRows = 0 Then
                MsgBox("Error.", vbQuestion)
            Else
                Me.Hide()
                Form2.Show()
            End If
        Catch ex As MySqlException
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Faika
  • 11
  • 2
  • Yikes. It is **NOT OKAY** to use string concatenation like this to build your SQL statements. Also, it is **NOT OKAY** to store passwords in your database like that. This is **REALLY BAD**. Like, lawsuit and causing-your-customers-to-lose-their-life-savings bad. – Joel Coehoorn Feb 06 '23 at 16:09
  • As for the actual issue, it's asking you to look at the inner exception. You can do at least that much by changing the MessageBox like this: `MessageBox.Show(ex.InnerException.Message)` – Joel Coehoorn Feb 06 '23 at 16:10
  • It is recommended that you update the question with the [Exception.InnerException Property](https://learn.microsoft.com/en-us/dotnet/api/system.exception.innerexception?view=net-7.0#system-exception-innerexception). – Jiachen Li-MSFT Feb 08 '23 at 02:06

0 Answers0