对于个人项目,我试图使用MySQL来访问我创建的存储图像的数据库。我正在使用C#编写脚本,但我的连接拒绝打开。这是我的代码片段(相关部分):
using MySql.Data.MySqlClient;
string cs ="Server=localhost;Database=test;Uid=root;Pwd=password;";
MySqlConnection conn = null;
MySqlDataReader rdr = null;
try
{
conn = new MySqlConnection(cs);
conn.Open();
string stm = "SELECT * FROM images";
MySqlCommand cmd = new MySqlCommand(stm, conn);
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
//do stuff
}
catch (Exception ex)
{
print (ex.ToString());
}
finally
{
if (rdr != null)
{
rdr.Close();
}
if (conn != null)
{
conn.Close();
}
}
我已经设置了断点,罪魁祸首是conn.Open()函数。此时它会引发异常:
System.TypeInitializationException:MySql.Data.MySqlClient.MySqlTrace的类型初始化程序抛出异常---> System.MissingMethodException:找不到方法:'System.Configuration.IConfigurationSectionHandler.Create'。在System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(System.String configKey)[0x00000] in:0 in System.Configuration.ConfigurationManager.GetSection(System.String sectionName)[0x00000] in:0 at System .Configuration.ConfigurationSettings.GetConfig(System.String sectionName)[0x00000] in:0 at System.Diagnostics.DiagnosticsConfiguration.get_Settings()[0x00000] in:0 at System.Diagnostics.TraceSource..ctor(System.String name,SourceLevels) sourceLevels)[0x00000] in:0,System.Diagnostics.TraceSource..ctor(System.String name)[0x00000] in:0 at MySql.Data.MySqlClient.MySqlTrace..cctor()[0x00000] in:0
---内部异常堆栈跟踪结束---在MySql.Data.MySqlClient.Driver.Create(MySql.Data.MySqlClient.MySqlConnectionStringBuilder设置)[0x00000]中:0 UnityEngine.MonoBehaviour:print(Object)UIScript:Start( )(在Assets / UIScript.cs:123)
听起来像是一个旧的/不匹配的dll,但我带来了MySql.Data,I18N和I18N.West作为我在Google上搜索时提出的一些解决方案。我已经用完了建议的修复程序,我希望有人可以提供帮助。我正在使用MySQL 5.6和.Net Connector 5.6.6。