Unity C#应用程序KeyNotFoundException [英] Unity C# application KeyNotFoundException

查看:6843
本文介绍了Unity C#应用程序KeyNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用unity尝试连接到MySQL数据库。
数据库运行正常,代码运行良好(在Visual studio 2010中)。
但是当以下内容在Unity中运行时:

I am using unity to try and connect to a MySQL database. The database runs fine, the code runs fine (in Visual studio 2010). However when the following is ran inside Unity:

// Connect to database
private static void openSqlConnection() {
    string connectionString = "Server=localhost;Database=league;Uid=android;Pwd=secret;";
    connection = new MySqlConnection(connectionString);
    try{
        connection.Open();
        Debug.Log("Connected to database.");
    }
    catch(MySql.Data.MySqlClient.MySqlException ex){
        Debug.Log(ex.Number);
        Debug.Log(ex.Message);
    }
}

此代码将引发以下错误:

This code will throw the following error:

KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[System.String,System.Object].get_Item (System.String key) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
MySql.Data.MySqlClient.MySqlConnectionStringBuilder.get_ExceptionInterceptors ()

这是一个为PC编译(在编辑器中运行),据我的知识,这段代码运行在visual studio与完全相同的MySQL DLL。为什么会抛出这个奇怪的异常?我真的想要一个简单的方法来连接到我的SQL数据库从内部统一。

This is a build for PC (ran in the editor) and to my knowledge this code runs in visual studio with the exact same MySQL DLL. Why does it throw this odd exception? I would really like an easy way to connect to my SQL Database from inside unity.

我使用的dll是:

MySQL\Connector NET 6.7.4\Assemblies\v2.0\MySql.Data.dll

而且try catch块似乎在这里没有用。

And the try catch block seems to be useless here.

推荐答案

使用此问题提供的dll: http://answers.unity3d .com / questions / 216372 / problem-with-mysql-connection.html
不知怎的,它神奇地修复它。我没有线索这个人使用哪个DLL,或在哪里得到更新版本的它。任何想法?

Using the dll provided with this question: http://answers.unity3d.com/questions/216372/problem-with-mysql-connection.html Somehow it magically fixes it. I have however no clue which DLL this guy used, or where to get the updated version of it. Any ideas?

这篇关于Unity C#应用程序KeyNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆