Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Unity Android MySQL连接函数失败:索引超出数组边界_C#_Mysql_.net_Visual Studio_Unity3d - Fatal编程技术网

C# Unity Android MySQL连接函数失败:索引超出数组边界

C# Unity Android MySQL连接函数失败:索引超出数组边界,c#,mysql,.net,visual-studio,unity3d,C#,Mysql,.net,Visual Studio,Unity3d,我有一个类来处理客户端和数据库(MySQL)之间的所有数据库交互(我知道并理解我不应该允许直接访问数据库) 我没有使用数组来存储读卡器的内容,下面是调用此示例的行(它发生在所有数据库交互中,不仅仅是此交互,也不仅仅是此数据库查询函数): 我还在一个更基本的项目中尝试了它,以获取Android返回的核心错误消息: 01-01 17:23:48.307: E/Unity(10476): IndexOutOfRangeException: Index was outside the bounds of

我有一个类来处理客户端和数据库(MySQL)之间的所有数据库交互(我知道并理解我不应该允许直接访问数据库)

我没有使用数组来存储读卡器的内容,下面是调用此示例的行(它发生在所有数据库交互中,不仅仅是此交互,也不仅仅是此数据库查询函数):

我还在一个更基本的项目中尝试了它,以获取Android返回的核心错误消息:

01-01 17:23:48.307: E/Unity(10476): IndexOutOfRangeException: Index was outside the bounds of the array. 
01-01 17:23:48.307: E/Unity(10476): at System.Diagnostics.TraceInternal.get_AppName () [0x0000e] in <ac210d81537245bc838518cc8e845861>:0 
01-01 17:23:48.307: E/Unity(10476): at System.Diagnostics.TraceInternal.TraceEvent (System.Diagnostics.TraceEventType eventType, System.Int32 id, System.String format, System.Object[] args) [0x0003d] in <ac210d81537245bc838518cc8e845861>:0 
01-01 17:23:48.307: E/Unity(10476): at System.Diagnostics.Trace.TraceError (System.String message) [0x00000] in <ac210d81537245bc838518cc8e845861>:0 
01-01 17:23:48.307: E/Unity(10476): at MySql.Data.MySqlClient.MySqlTrace.LogError (System.Int32 id, System.String msg) [0x00028] in <326e9aab93854e739606c3572c385a34>:0 
01-01 17:23:48.307: E/Unity(10476): at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver () [0x00031] in <326e9aab93854e739606c3572c385a34>:0 
01-01 17:23:48.307: E/Unity(10476): at MySql.Data.MySqlClient.MySqlPool.GetConnection () [0x0001c] in <326e9aab93854e739606c3572c385a34>:0 
01-01 17:23:48.307: E/Unity(10476): at MySql.Data.MySqlClient.MySqlConnection.Open () [0x000f3] in <326e9aab93854e739606c3572c385a34>:0 
01-01 17:23:48.307: E/Unity(10476): at texttest1.Start () [0x00011] in <dd75ac8e3f854a97ac132dae6ec658fd>:0
01-01 17:23:48.307:E/Unity(10476):IndexOutOfRangeException:索引超出了数组的边界。
01-01 17:23:48.307:E/Unity(10476):在System.Diagnostics.TraceInternal.get_AppName()[0x0000e]中:0
01-01 17:23:48.307:E/Unity(10476):位于System.Diagnostics.TraceInternal.TraceEvent(System.Diagnostics.TraceEventType事件类型,System.Int32 id,System.String格式,System.Object[]args)[0x0003d]in:0
01-01 17:23:48.307:E/Unity(10476):在System.Diagnostics.Trace.TraceError(System.String消息)[0x00000]中:0
01-01 17:23:48.307:E/Unity(10476):位于MySql.Data.MySqlClient.MySqlTrace.LogError(System.Int32 id,System.String msg)[0x00028]in:0
01-01 17:23:48.307:E/Unity(10476):位于:0中的MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()[0x00031]
01-01 17:23:48.307:E/Unity(10476):位于MySql.Data.MySqlClient.MySqlPool.GetConnection()[0x0001c]中:0
01-01 17:23:48.307:E/Unity(10476):位于MySql.Data.MySqlClient.MySqlConnection.Open()[0x000f3]in:0
01-01 17:23:48.307:E/Unity(10476):在文本test1.Start()处[0x00011]在:0

我可能在这里错过了一些非常简单的东西,但如果有任何帮助,我将不胜感激

结果集中没有这样命名(
MAX(DT_Stamp)
)。我会在你的projection子句中使用
作为名称
,并以这种方式引用它。

我找到了答案:


为了让Android设备能够进行外部通信,您需要将I18N.dll和I18N.West.dll添加到您的资产中,这就是Unity Editor和Android APK中工作的区别。

嘿,感谢您的快速回复!我明白你的意思,但是SQL语句的返回值通过MySQL数据库返回一个name属性为“MAX(DT_Stamp)”的值。就像我说的,它在unity客户机中工作非常好,只是在Android@JamesCoyle这可能只是特定mysql ado.net提供程序的问题。没错,但如果真是这样的话,它在Unity编辑器中肯定不会起作用吗?@JamesCoyle,谁知道呢。其中许多可能会有所不同,因为有非托管代码驱动其中一些。是不是
getDatabaseValue(“dt_stamp”,“从tbl_Store中选择MAX(dt_stamp)dt_stamp;”)
也失败了?嘿,是的,所以我用于“Simpler”版本的代码如下:`void Start(){connection=new MySqlConnection(connectionString);connection.Open();command=new MySqlCommand(“从tbl_存储中选择项_名称;”,connection);MySqlDataReader=command.ExecuteReader();text=GameObject.Find(“text”).GetComponent();reader.Read();text.text=reader[“项_名称”]。ToString();}`实际上不使用相同的查询,而且它在Monitor.bat中仍会产生相同的结果
01-01 15:21:14.141: I/Unity(23761): (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
01-01 15:21:14.829: I/Unity(23761): Database get failed (System Exception), query: SELECT MAX(DT_Stamp) FROM tbl_Store;
01-01 15:21:14.829: I/Unity(23761):  
01-01 15:21:14.829: I/Unity(23761): (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
01-01 15:21:14.829: I/Unity(23761): Exception Message: Index was outside the bounds of the array.
    DateTime DB_Date = getDatabaseValue<DateTime>("MAX(DT_Stamp)", "SELECT MAX(DT_Stamp) FROM tbl_Store;");
4 Hero Upgrade #1 100 1 2018-12-11 09:53:14 
5 Hero Upgrade #2 300 1 2018-12-11 09:53:14 
6 Hero Upgrade #3 700 1 2018-12-11 09:53:14 
01-01 17:23:48.307: E/Unity(10476): IndexOutOfRangeException: Index was outside the bounds of the array. 
01-01 17:23:48.307: E/Unity(10476): at System.Diagnostics.TraceInternal.get_AppName () [0x0000e] in <ac210d81537245bc838518cc8e845861>:0 
01-01 17:23:48.307: E/Unity(10476): at System.Diagnostics.TraceInternal.TraceEvent (System.Diagnostics.TraceEventType eventType, System.Int32 id, System.String format, System.Object[] args) [0x0003d] in <ac210d81537245bc838518cc8e845861>:0 
01-01 17:23:48.307: E/Unity(10476): at System.Diagnostics.Trace.TraceError (System.String message) [0x00000] in <ac210d81537245bc838518cc8e845861>:0 
01-01 17:23:48.307: E/Unity(10476): at MySql.Data.MySqlClient.MySqlTrace.LogError (System.Int32 id, System.String msg) [0x00028] in <326e9aab93854e739606c3572c385a34>:0 
01-01 17:23:48.307: E/Unity(10476): at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver () [0x00031] in <326e9aab93854e739606c3572c385a34>:0 
01-01 17:23:48.307: E/Unity(10476): at MySql.Data.MySqlClient.MySqlPool.GetConnection () [0x0001c] in <326e9aab93854e739606c3572c385a34>:0 
01-01 17:23:48.307: E/Unity(10476): at MySql.Data.MySqlClient.MySqlConnection.Open () [0x000f3] in <326e9aab93854e739606c3572c385a34>:0 
01-01 17:23:48.307: E/Unity(10476): at texttest1.Start () [0x00011] in <dd75ac8e3f854a97ac132dae6ec658fd>:0