Quantcast
Channel: MySQL Forums - Connector/C++
Viewing all articles
Browse latest Browse all 527

Unity Android MySQL connection function failing: Index was outside the bounds of the array. (1 reply)

$
0
0
I have a class to handle all of the database interactions between the client and database (MySQL) (I know and understand that I shouldn't allow direct access to a database)

public T getDatabaseValue<T>(string value, string query)
{
try
{
connection = new MySqlConnection(connectionString);
connection.Open();
command = new MySqlCommand(query, connection);
MySqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
return (T)reader[value];
}
else
return default(T);
}
catch (MySqlException SQLex)
{
Debug.Log("Database get failed (SQL Exception), query: " + query);
Debug.Log("Exception Message: " + SQLex.Message);
return default(T);
}
catch (System.Exception ex)
{
Debug.Log("Database get failed (System Exception), query: " + query);
Debug.Log("Exception Message: " + ex.Message);
return default(T);
}
}
This works flawlessly in the editor. When building and running on Android I get this error message via Monitor:

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.
I'm not using an array to store the contents of the reader, here is the line that calls this example (it happens for all database interactions, not just this one, and not just this database querying function):

DateTime DB_Date = getDatabaseValue<DateTime>("MAX(DT_Stamp)", "SELECT MAX(DT_Stamp) FROM tbl_Store;");
Here's the contents of tbl_Store:

(Item_ID (int)), (Item_Name (varchar)), (Item_Price (float)), (In_Use (bit)), (DT_Stamp (datetime))

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

I'm probably missing something really simple here but any help would be greatly appreciated!

Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>