Artihmetic Overflow when calling STArea() on geography instance

Category: sql server spatial

Question

Xavier Fischer on Wed, 03 Apr 2013 10:15:31


Hello,

I have a strange behavior in my code execution. I'm getting features from my SQL Server database and performing STArea() calls on each retrieved instance.

Every instance is valid and not self intersecting.

Then sometimes, I get an "Arithmetic Overflow" exception. If I call again the same method STArea(), it works. 

double area= 0d;
try 
{
  area = p_NativeGeography.STArea().Value;					}
catch (System.OverflowException)
{
  // Sometimes getting "Arithmetic Overfow."
  // recall the same STArea()
  //
  area = p_NativeGeography.STArea().Value;
  
  // .. never crashes

}
finally
{
  // Doing stuff here...
}

Stack trace is 

   at System.Data.SqlTypes.SqlDouble..ctor(Double value)
   at System.Data.SqlTypes.SqlDouble.op_Implicit(Double x)
   at Microsoft.SqlServer.Types.SqlGeography.STArea()


Do you have any idea of what's going on ? SQL CLR 2008 Types are installed on computer running the program.

Thank you