3

I am facing the error on the below code while i created a function call class at app_code.

My error is showing -->BC30002: Type 'MySqlConnection' is not defined. Please help.Thanks!

Imports System.Data
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports MySql.Data.MySqlClient

Namespace check90daysreturn

Public Class Check90days
    Public Function check(ByVal datereceived As String, ByVal shipdate As String, ByVal partsn As String)

        Dim con As String = ConfigurationManager.ConnectionStrings("xxxConnectionString").ConnectionString
        Dim Sql As New MySqlConnection(con)

        Dim reader2 As Object
        Dim theQuery2 As String = "SELECT Max(shipmentdate) FROM prc.tbsrparts t WHERE Substring(partsn, 17, 11) = '" + partsn.ToString + "'" 'get latest shipment date from database
        Dim command2 As New MySqlCommand(theQuery2, Sql)
        reader2 = command2.ExecuteScalar

        'send auto email
        Dim mailmssg As New MailMessage()
        Dim smtp_client As New SmtpClient

        mailmssg.IsBodyHtml = True
        smtp_client = New SmtpClient
        smtp_client.Host = "ll.smtp.xxxxx.com"
        smtp_client.Port = 25

        mailmssg.From = New MailAddress("zzz@yahoo.com")

        mailmssg.CC.Add("xxxx@yahoo.com")
        mailmssg.Subject = "(Testing)"
        mailmssg.Body = "Testing"

        smtp_client.DeliveryMethod = SmtpDeliveryMethod.Network
        smtp_client.Send(mailmssg)



    End Function
End Class
End Namespace
Ashley Hooithin
  • 53
  • 1
  • 1
  • 6
  • I had similar problem. I went to Visual Studio's Project Properties, Under References, for some reason for MySql.Data the Path was not found so I had to browse to the correct path to fix the issue. – Dogahe Sep 14 '15 at 14:31

4 Answers4

2

I got the same error.

After adding

Imports MySql.Data.MySqlClient;

, and a reference to the MySql.Data.dll I got 'MySqlConnection is not defined'.

I have fixed it by adding the reference MySql.Data.dll from the older version that is V2.0 instead of V4.5.

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
Viral
  • 21
  • 2
  • 1
    This worked for me, too, except I used the V4.0 instead of V4.5. Thanks. – Sastreen Jul 07 '16 at 14:35
  • ... I have fixed it by adding the reference MySql.Data.dll from the older version that is V2.0 instead of V4.5 and so how do you do that fixing – webs Jun 20 '20 at 08:57
1

In my scenario,the problem was fairly simple. The project I worked on was targeting framework version 4.5 of .Net where as MySql.Data was targeted towards .Net 4.5.2 version. MySql.Data version should be lower or equal to the project target framework version. So I changed the project target version to 4.5.2 and it compiled successfully. Hope that helps someone.

hcoder
  • 103
  • 11
0

So you have already added Imports MySql.Data.MySqlClient. But have you also added a reference to the MySql.Data.dll?

How do I add a reference to the MySQL connector for .NET?

Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
0

Sometimes adding the refernce to MySql.Data.dll becomes problematic if it is not listed in the reference tab of your project's prpoerties. In this case if you are sure that you have installed the MySql connector then simply choose add reference, on the dialog box shown choose browse then navigate to the folder inwhich it is installed in my case it is C:\Program Files (x86)\MySQL\Connector NET 6.10\Assemblies\v4.5.2 then select MySql.Data.dll click on open then add and it should work alright