After several attempts, I finally managed to use DataBase access in Unity with System.Data.Odbc
.
I know the connection and the query works, because I can do this :
cmd = new OdbcCommand(req);
cmd.Connection = accessConnection;
OdbcDataReader reader = cmd.ExecuteReader();
while (reader.Read()) {
Debug.Log("test: "+reader[0]); // This works fine
}
But when I try to use a DataTable, it does crash pretty badly.
I tried :
cmd = new OdbcCommand(req);
cmd.Connection = accessConnection;
OdbcDataReader reader = cmd.ExecuteReader();
output = new DataTable();
output.Load(reader); // This line crash somehow
reader.Close();
Here is the exception details I catched :
TargetSite: Int32 GetColumnAttribute(Int32, FieldIdentifier)
Source: System.Data
Message: Object reference not set to an instance of an object
StackTrace: at System.Data.Odbc.OdbcDataReader.GetColumnAttribute (Int32 column, FieldIdentifier fieldId) [0x00000] in <filename unknown>:0
at System.Data.Odbc.OdbcDataReader.GetSchemaTable () [0x00000] in <filename unknown>:0
at System.Data.Common.DataAdapter.BuildSchema (IDataReader reader, System.Data.DataTable table, SchemaType schemaType, MissingSchemaAction missingSchAction, MissingMappingAction missingMapAction, System.Data.Common.DataTableMappingCollection dtMapping) [0x00000] in <filename unknown>:0
at System.Data.DataTable.Load (IDataReader reader, LoadOption loadOption) [0x00000] in <filename unknown>:0
at System.Data.DataTable.Load (IDataReader reader) [0x00000] in <filename unknown>:0
at DataBase.Execute (System.String req) [0x00063] in D:\Unity Project\Assets\DataBase.cs:131
UnityEngine.Debug:LogError(Object)
DataBase:Execute(String) (at Assets/DataBase.cs:150)
ModelHandler:Start() (at Assets/ModelHandler.cs:34)
Does anyone have an idea to fix this ?
For information, I also tried with an OdbcDataAdapter, with the Fill method, an I've cached the same kind of issue.