Hi guys im using VisualStudio2017 to make a chat program from a youtube video
i keep getting an error and wondered if one of you might be able to help me out.
Exception thrown: 'System.InvalidOperationException' in MySql.Data.dll
The code:
Imports System.Security.Cryptography
Imports System.IO
Imports MySql.Data.MySqlClient
Module Con_Add
Public usernamefriend As String
Public Conn As New MySqlConnection
Public ConTemp As New MySqlConnection
Public MsgSubject As String = String.Empty
Sub ConTempOpen()
ConTemp.ConnectionString = "server=localhost" & My.Settings.Host & "; user id=root" & My.Settings.User & "; password=" & My.Settings.Pass & "; database=db_chat " & My.Settings.dbName
Try
ConTemp.Open()
Catch ex As Exception
MsgBox(ex.Message & vbNewLine & "Check you connection", MsgBoxStyle.Critical, "Can not connect to the database")
Application.Exit()
End Try
End Sub
Sub OpenConnection()
Conn.ConnectionString = "server=localhost" & My.Settings.Host & "; user id=root" & My.Settings.User & "; password=" & My.Settings.Pass & "; database=db_chat " & My.Settings.dbName
Try
ConTemp.Open()
Catch ex As Exception
MsgBox(ex.Message & vbNewLine & "Check you connection", MsgBoxStyle.Critical, "Can not connect to the database")
Application.Exit()
End Try
End Sub
Function MDSEncrypter(ByVal strPass As String) As String
Dim Hasher As New MD5CryptoServiceProvider
Dim PasswordBytes As Byte() = New Byte(strPass.Length + 3) {}
Dim HashBytes As Byte()
For i As Integer = 0 To strPass.Length - 1
PasswordBytes(i) = (CByte(Asc(strPass(i))))
Next
PasswordBytes(strPass.Length) = CByte(90)
PasswordBytes(strPass.Length + 1) = CByte(85)
PasswordBytes(strPass.Length + 2) = CByte(66)
PasswordBytes(strPass.Length + 3) = CByte(73)
HashBytes = Hasher.ComputeHash(PasswordBytes)
Dim NewHashBytes As Byte() = New Byte(HashBytes.length + 3) {}
For j As Integer = 0 To HashBytes.length - 1
NewHashBytes(j) = HashBytes(j)
Next
NewHashBytes(HashBytes.Length) = CByte(90)
NewHashBytes(HashBytes.length + 1) = CByte(85)
NewHashBytes(HashBytes.length + 2) = CByte(66)
NewHashBytes(HashBytes.length + 3) = CByte(73)
strPass = Convert.ToBase64String(NewHashBytes)
Return strPass
End Function
Function ImageToBytes(ByVal imgPath As String) As String
Try
Dim Image_DP As Image = Image.FromFile(imgPath)
Dim memories As MemoryStream = New MemoryStream()
Image_DP.Save(memories, System.Drawing.Imaging.ImageFormat.Png)
Dim ImageBytes As Byte() = memories.ToArray()
Dim StringImage As String = Convert.ToBase64String(ImageBytes)
Return StringImage
Catch ex As Exception
MsgBox(ex.Message & vbNewLine & "Failed to convert image to bytes.", MsgBoxStyle.Exclamation, "Error")
End Try
End Function
End Module