18

Before I used MS SQL but in a new project I use mysql and when I run our application I get this error

Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name 'MySql' could not be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 4:  using System.Text;
Line 5:  using System.Web;
Line 6:  `using MySql.Data.MySqlClient;    this namespace is not working 
Line 7:  using System.Data.SqlTypes;

How can I solve this problem?

13 Answers 13

18

To solve this problem download MySql.Data.dll from

https://www.dllme.com/dll/files/mysql_data_dll.html

Then right click on your project name, click on add reference and select MySql.Data.dll file

Sign up to request clarification or add additional context in comments.

2 Comments

thanks this work for me too save my day thank a lot (Visual studio 2012)
@allexiusw - Thanks for your message. New link added. :)
12

In Project solution frame find References file and right click on it, then choose "Add Reference" on the menu, then click on .NET tab, find MySql.Data and add it to References file.

Comments

9

1) Right-click on References, select Add Reference.

2) Select .NET tab. Check what the text directly under the tabs says, example: "Filtered to: .NET Framework 4 Client Profile".

3) Click on the Browse tab.

4) Browse to the MySql folder and go on into the Assemblies folder, example: C:\Program Files (x86)\MySQL\Connector NET 6.8.3\Assemblies

5) Select the version folder which matches the text under 2), example: "v4.0"

6) Add MySql.Data.dll

Comments

4

On Windows 7 64bit

1) download https://www.cryptool.org/trac/CrypTool2/export/2020/trunk/AppReferences/x64/MySql.Data.dll

2) paste a copy of MySql.Data.dll in folder /bin

3) create the database and table e.g.

CREATE DATABASE my_db ;

USE my_db; 

CREATE TABLE `my_users` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(100) NOT NULL default '',
`country` varchar(100) NOT NULL default '',
PRIMARY KEY  (`id`));

INSERT INTO `my_users` VALUES (null,'Mark','Canada');

INSERT INTO `my_users` VALUES (null,'Frank','US');

4) create the following page Default.aspx

<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="MySql.Data.MySqlClient" %>
<script runat="server">

protected void Page_Load(Object sender, EventArgs e)
{
    MySqlConnection myConnection = new MySqlConnection(
    "server=localhost; user id=root; password=zZxX11++; database=my_db; pooling=false;");

    String strSQL = "SELECT * FROM my_users;";

    MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(strSQL, myConnection);

    DataSet myDataSet = new DataSet();
    myDataAdapter.Fill(myDataSet, "my_users");

    MySQLDataGrid.DataSource = myDataSet;
    MySQLDataGrid.DataBind();
}

</script>
<html>
<head>
    <title>MySQL Query</title>
</head>
<body>
    <form runat="server">
    <asp:DataGrid id="MySQLDataGrid" runat="server"></asp:DataGrid>
    </form>
</body>
</html> 

5) download http://www.codeguru.com/dbfiles/get_file/060216.zip?id=19637&lbl=060216_ZIP

6) extract the above and place GridView.aspx in your project folder

7) run the Default.aspx

8) The output should be:

Table content:

<table cellspacing="0" rules="all" border="1" id="MySQLDataGrid" style="border-collapse:collapse;">
    <tbody><tr>
        <td>id</td><td>name</td><td>country</td>
    </tr><tr>
        <td>1</td><td>Mark</td><td>Canada</td>
    </tr><tr>
        <td>2</td><td>Frank</td><td>US</td>
    </tr>
</tbody></table>

Comments

0

You need to add a reference to the MySQL.Data.dll (if you don't have it, you can download it by following the link posted by Lukasz)

Comments

0

You should download MySQL.Data.dll.

Because MySql is not in .Net framework library, so if you just click "Add Reference" in your project on VS, you cannot find it.

After you download it, you can click Add Reference to put it into your project.

Comments

0

If you use MySql you need to add to the references MySql.Data.MySqlClient and use Mysqlconnection, that worked for me.

Comments

0

If you are using Unity Development IDE:

1) Right-click on References, select Edit Reference. enter image description here

2) Make Sure that System.Data(in All Tab) and MySQl.Data is checked(in .NET Assembly package).

Note: If MySQl.Data is not there, download it from http://ul.to/g2o3a3h1 and then upload it to Unity Environment using Assets->Import Package->Custom Package.

3) Reopen your database handler file and CLEAN and REBUILD your code. If still reference error persist, do the step 1 and 2

Comments

0

You might not need to download the dll, you might already have it. View->Object Browser->.NET-> find MySql.Data->Add->OK -> Add to References enter image description here

Comments

0

To get MySql.Data.MySqlClient class or dll file , you have to download it first from third party: https://www.cryptool.org/trac/CrypTool2/export/2020/trunk/AppReferences/x64/MySql.Data.dll

THEN:: 1. Click add reference 2. click "Browse" button at the button 3. go to the path of downloaded file. 4. choose dll file and select 5. add the file as reference and it will work

Comments

0

In my case, the problem was MySql.Data version. I changed it from 8.0.20 to 6.10.9 (in Managing NuGet Packages) and it started working.

Comments

0

Even if you already have included MySql connector using the references it still might not work. The reason is you might be running on an older version but the connector installed is not compatible with the older version. So go to references -> manage Nuget packages. Then in that window search for mysql.data. Then keep adjusting the version number until it lands on the correct version that is compatible!!!!!!

Comments

0

In case of dotnet core 3.0

  1. Add Mysql.Data Package using NuGET Package Manager
  2. in appsettings.json write connection string for example:

    "AllowedHosts": "*", "ConnectionStrings": { "Default": "server=localhost;user=root;password='123';database=DbName" }

  3. in Startup.cs file->in ConfigureServices method Add

    services.AddTransient(_ => new MySqlConnection(Configuration["ConnectionStrings:Default"]));

It is working fine in my application

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.