12

Currently trying to create a connection to a MySql Database. When I added

using MySql.Data; using MySql.Data.MySqlClient;

to my class I recieved the typical "The type or namespace name ... could not be found". A little searching made me realize I was missing the MySql.Data.dll.

I used Packet Manager console to install MySql.Data:

PM> Install-Package MySql.Data

I verified that it was installed via Tools > NuGet Package Manager > Manage NuGet Packages for Solutions, but I was still getting the build error.

At this point I figured, since the PM downloaded the .dll I'll just manually reference it via References > Add Reference > Browse > Select MySql.Data.dll.

Great!! The red squiggly went away on my using and intellisense started working for classes inside the MySql.Data namespace:

enter image description here

Fast forward 10 mins, I finish writing my test class and hit Build and error comes back:

enter image description here

So in summary, using PM to install MySql.Data got me no where. Manually adding the reference of MySql.Data.dll got my intellisense to recognize the namespace and classes, but when it comes to building I still get the error.

Pretty stumped. Anyone seen this?

Flippi
  • 380
  • 1
  • 2
  • 16
  • 1
    Came across this post https://stackoverflow.com/questions/1102281/how-do-i-add-a-reference-to-the-mysql-connector-for-net Hope it helps solve your issue. – Dev Nov 08 '17 at 06:05
  • Thanks for the link, but I've already done the solutions provided there. Step 4. of the marked solution even works for me: "At the top of your code, add using MySql.Data.MySqlClient;. If you've added the reference correctly, IntelliSense should offer to complete this for you." This is true, it does do this and you can see in my screenshot that IntelliSense is working, but at compile time I still get there error... – Flippi Nov 08 '17 at 13:54

5 Answers5

18

Solved this issue! Turns out the newest MySql.Data.dll is built off of .Net Framework 4.5.2, while my project was using .Net Framework 3.5 Client Profile.

Changing my project's framework to 4.5.2 solved the issue. It's quite strange that VS doesn't give a better error message.

To change your project's framework right click on your project (not the solution), select Properties -> Application -> Target framework. The target framework is a dropdown on that page.

I came to this realization thanks to another stackoverflower question: Namespace not recognized (even though it is there)

Flippi
  • 380
  • 1
  • 2
  • 16
6

In terminal after navigating to your project directory, run the following commands

dotnet add package MySql.Data -v 8.0
mruanova
  • 6,351
  • 6
  • 37
  • 55
0

In this situation MySQL dll files very new. You can download older dll files and includ in your project. I prefer this version. It works for me MySql.Data.DLL

Downloaded the .dll You'll just manually reference it via References > Add Reference > Browse > Select MySql.Data.dll

Tân
  • 1
  • 15
  • 56
  • 102
Bahodir
  • 11
  • 1
  • Why is this downvoted? This solved my problem (though I didn't have to go download a new dll... if you have MySQL installed on your computer the dll will be there somewhere). – Jess Apr 06 '19 at 16:52
0

I changed the reference of MySql.Data from a previous version to the current one and the error was gone. You can select that by clicking on add reference and then on the left side find recent if you have used it, change it to a current version, in my case it was from 8.0.23.0 to 8.0.25.0

Dharman
  • 30,962
  • 25
  • 85
  • 135
-1

I too had the similar issue. I had 3 projects -namely , Data Access Layer, Business LogicLayer and WebApplication. I went to "WebApplication" project property/Application and change the .Net Framework from 4.6.1 to 4.6 Then again it complained saying, the referenced project has higher framework version, so again i right click on the Business LogicLayer and DataAccessLayer and change the .Net Framework to 4.6 instead of 4.6.1. Now the build is successful without any noise ( no warning/no error).

I am able to successfully publish the source code as well. But still the page is not coming up, the error message in the browser is as below :

Server Error in '/' Application. The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4075.0

But I think this is separate error. Now i am trying to fix this error.

sri harsha
  • 676
  • 6
  • 16