简体   繁体   English

错误 CS0246:找不到类型或命名空间名称“MySql”

[英]error CS0246: The type or namespace name 'MySql' could not be found

im trying to connect to my mysql database for my project but im getting the following error:我试图为我的项目连接到我的 mysql 数据库,但我收到以下错误:

error CS0246: The type or namespace name 'MySql' could not be found错误 CS0246:找不到类型或命名空间名称“MySql”

full error:完整错误:

[Running] mono "C:\\Users\\Aidan\\AppData\\Roaming\\Code\\User\\cs-script.user\\cscs.exe" "d:!computer science!!NEA!\\test stuff\\sql\\c# sql test 1.cs" Error: Specified file could not be compiled. [运行] mono "C:\\Users\\Aidan\\AppData\\Roaming\\Code\\User\\cs-script.user\\cscs.exe" "d:!computer science!!NEA!\\test stuff\\sql\\c# sql test 1 .cs”错误:无法编译指定的文件。

csscript.CompilerException: d:!computer science!!NEA!\\test stuff\\sql\\c# sql test 1.cs(3,7): error CS0246: The type or namespace name 'MySql' could not be found (are you missing a using directive or an assembly reference?) d:!computer science!!NEA!\\test stuff\\sql\\c# sql test 1.cs(4,7): error CS0246: The type or namespace name 'MySql' could not be found (are you missing a using directive or an assembly reference?) d:!computer science!!NEA!\\test stuff\\sql\\c# sql test 1.cs(5,7): error CS0246: The type or namespace name 'MySql' could not be found (are you missing a using directive or an assembly reference?) csscript.CompilerException: d:!computer science!!NEA!\\test stuff\\sql\\c# sql test 1.cs(3,7): 错误 CS0246: 找不到类型或命名空间名称“MySql”(您是否遗漏了) using 指令或程序集引用?)d:!computer science!!NEA!\\test stuff\\sql\\c# sql test 1.cs(4,7): error CS0246: The type or namespace name 'MySql' could not be找到(您是否缺少 using 指令或程序集引用?) d:!computer science!!NEA!\\test stuff\\sql\\c# sql test 1.cs(5,7): error CS0246: The type or namespace name '找不到 MySql'(您是否缺少 using 指令或程序集引用?)

at csscript.CSExecutor.ProcessCompilingResult (System.CodeDom.Compiler.CompilerResults results, System.CodeDom.Compiler.CompilerParameters compilerParams, CSScriptLibrary.ScriptParser parser, System.String scriptFileName, System.String assemblyFileName, System.String[] additionalDependencies) [0x00102] in :0 at csscript.CSExecutor.Compile (System.String scriptFileName) [0x0080d] in :0 at csscript.CSExecutor.ExecuteImpl () [0x005a1] in :0在 csscript.CSExecutor.ProcessCompilingResult (System.CodeDom.Compiler.CompilerResults 结果, System.CodeDom.Compiler.CompilerParameters compilerParams, CSScriptLibrary.ScriptParser parser, System.String scriptFileName, System.String assemblyFileName, System.String[] additionalDependencies) [0x00102]在 :0 在 csscript.CSExecutor.Compile (System.String scriptFileName) [0x0080d] 在 :0 在 csscript.CSExecutor.ExecuteImpl () [0x005a1] 在 :0

[Done] exited with code=1 in 5.388 seconds [完成] 在 5.388 秒内以代码 = 1 退出

im using visual studio code, (visual studio is broken, says free trial has expired for community)我使用的是visual studio代码,(visual studio坏了,说社区的免费试用期已过)

when looking at other problems like this online i wasnt able to find anything that fixed it, some sites were going on about dlls and stuff but i wasnt able to understand what they were trying to do, so please explain exactly what it is i need to do.在网上查看类似这样的其他问题时,我无法找到任何修复它的东西,有些网站正在处理 dll 和其他内容,但我无法理解他们想要做什么,所以请准确解释我需要做什么做。

im using c#, running the server off the same computer and i am able to connect to it and edit the databases using popsql.我使用 C#,在同一台计算机上运行服务器,我能够连接到它并使用 popsql 编辑数据库。

here is the code i am using:这是我正在使用的代码:

using System;
using System.Data;

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

public class Tutorial2
{
    public static void Main()
    {
        string connStr = "server=localhost;user=****;database=*****;port=****;password=***********";
        MySqlConnection conn = new MySqlConnection(connStr);
        try
        {
            Console.WriteLine("Connecting to MySQL...");
            conn.Open();

            string sql = "SELECT Name, HeadOfState FROM Country WHERE Continent='Oceania'";
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            MySqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                Console.WriteLine(rdr[0]+" -- "+rdr[1]);
            }
            rdr.Close();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }

        conn.Close();
        Console.WriteLine("Done.");
    }
}

(i replaced password etc with stars) (我用星星替换了密码等)

If you are getting errors on your using tags, it is most likely not your code that is wrong but the files your are tying to reference.如果您在使用标签时遇到错误,很可能不是您的代码有问题,而是您要引用的文件。 Some of the MySQL dll's may be corrupt or missing.某些 MySQL dll 可能已损坏或丢失。

You can try the following:您可以尝试以下操作:

  1. Check project references.检查项目参考。 If MySql exists in references but has aa warning (a yello triangle), then need to delete and add the .dll again.如果引用中存在MySql但有警告(黄色三角形),则需要删除并再次添加.dll。 Easier way is to install a nuget package.更简单的方法是安装 nuget 包。

  2. Alternatively, check the Project's framework.或者,检查项目的框架。 If the .Net version of project is less than the MySql's one, then need to change the Project's target framework.如果项目的.Net 版本小于MySql 的版本,则需要更改项目的目标框架。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误 CS0246:找不到类型或命名空间名称“IApplicationBuilderExtensions” - error CS0246: The type or namespace name 'IApplicationBuilderExtensions' could not be found 错误 CS0246:找不到类型或命名空间名称“PlayerMotor” - error CS0246: The type or namespace name 'PlayerMotor' could not be found 错误CS0246:找不到类型或名称空间名称“ HtmlAgilityPack” - Error CS0246: The type or namespace name `HtmlAgilityPack' could not be found 错误 CS0246:找不到类型或命名空间名称“UnityEngine” - error CS0246: The type or namespace name 'UnityEngine' could not be found 错误 CS0246:找不到类型或命名空间名称“KustoConnectionStringBuilder” - error CS0246: The type or namespace name 'KustoConnectionStringBuilder' could not be found 错误CS0246:找不到类型或命名空间名称“AssemblyFileVersion” - Error CS0246: The type or namespace name 'AssemblyFileVersion' could not be found 错误 CS0246:找不到类型或命名空间名称“Newtonsoft” - Error CS0246: The type or namespace name 'Newtonsoft' could not be found 错误 CS0246:找不到类型或命名空间名称“CsvHelper” - error CS0246: The type or namespace name 'CsvHelper' could not be found 错误CS0246:找不到类型或名称空间名称'WebDriverWait'? - Error CS0246: The type or namespace name 'WebDriverWait' could not be found? CS0246:找不到类型或命名空间名称“System” - CS0246: The type or namespace name 'System' could not be found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM