Ashley Hooithin
Ashley Hooithin

Reputation: 53

Type 'MySqlConnection' is not defined

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("[email protected]")

        mailmssg.CC.Add("[email protected]")
        mailmssg.Subject = "(Testing)"
        mailmssg.Body = "Testing"

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



    End Function
End Class
End Namespace

Upvotes: 3

Views: 28046

Answers (4)

hcoder
hcoder

Reputation: 113

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.

Upvotes: 1

user8990420
user8990420

Reputation:

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

Upvotes: 0

Viral
Viral

Reputation: 31

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.

Upvotes: 3

Tim Schmelter
Tim Schmelter

Reputation: 460058

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?

Upvotes: 0

Related Questions