VERIFIED SOLUTION i
X

Resolve error: MapInfo.Data.MIException: Unable to parse statement in MapXtreme .NET

Issue

When running a MapXtreme .NET application the following error is encountered:

MapInfo.Data.MIException: Unable to parse statement error message when closing the table:

Stack Trace: Error: MapInfo.Data.MIException: Unable to parse statement : select "Obj" from "" where MI_Key = myKey: Invalid identifier (). 
at MapInfo.Data.MICommand.Prepare() 
at MapInfo.Data.MICommand.ExecuteReader() 
at MapInfo.Data.Feature.LoadIfNeeded() 
at MapInfo.Data.Feature.get_Geometry() 

/// <summary> 
/// Read the valid geom for a specific map object ID from a TAB file 
/// </summary> 
/// <param name="mapObjId"></param> 
/// <param name="batchDirPath"></param> 
/// <returns>MapFeature.Geomerty</returns> 
public Feature Get_Geom(int mapObjId, string batchDirPath) 

Feature f; 
MapInfo.Data.Table TabTable = null; 
MapInfo.Data.SearchInfo si = null; 
IResultSetFeatureCollection irfc = null; 
string[] ColumnSort = new string[] {"Obj"}; 

Console.WriteLine("Searching Tab file " + batchDirPath + " for MapObjID " + mapObjId.ToString()); 

try 

TabTable = MapInfo.Engine.Session.Current.Catalog.OpenTable(batchDirPath, "TabTable"); 

si = MapInfo.Data.SearchInfoFactory.SearchAll(); 
si.QueryDefinition.Columns = ColumnSort; 

// search for the value in the open table 
Console.WriteLine("Searching table for data"); 
irfc = MapInfo.Engine.Session.Current.Catalog.Search(TabTable, si); 

// get the value back from the table 
f = irfc[0]; 

// close the table 
Console.WriteLine("Closing the MapInfo.Catalog table"); 

MapInfo.Engine.Session.Current.Catalog.CloseTable(TabTable.Alias); 

irfc.Close(); 

return f; 

catch (MIException ex) 

Console.WriteLine("Closing the MapInfo.Catalog - close all - " + ex.ToString()); 
MapInfo.Engine.Session.Current.Catalog.CloseAll(); 
throw; 


Cause

Closing the Table before MapXtreme has finished with it

Resolution

UPDATED: September 19, 2017


Move the line 'MapInfo.Engine.Session.Current.Catalog.CloseTable(TabTable.Alias);' outside the Try loop

Environment Details

Products affected: MapXtreme .NET

Downloads

  • No Downloads