I Get a random/intermittent SQL timeout on this query looks like it generates a lot of processing from a simple query. Is this correct behavior?
I have a simple stored procedure like this:
CREATE PROCEDURE [dbo].[FindClosestXNearCoordinates]
@latitude decimal,
@longitude decimal
AS
BEGIN
SET NOCOUNT ON;
declare @emptyGUID uniqueidentifier
set @emptyGUID = cast(cast(0 as binary) as uniqueidentifier)
declare @radiusInMeters float
set @radiusInMeters = 3500 * 1609.344
declare @coordinatePoint as Geography
SET @coordinatePoint = geography::STGeomFromText('POINT(' + CAST(@longitude AS VARCHAR(20)) + ' ' + CAST(@latitude AS VARCHAR(20)) + ')', 4326)
declare @coordinateRadius as Geography
set @coordinateRadius = @coordinatePoint.STBuffer(@radiusInMeters);
select top 1 [b].[BaseId], [b].[Code], [b].[Name], [b].[Location], [b].[TerritoryId], [b].[Latitude], [b].[Longitude]
from XTable b
where ( b.GeoLocation.STIntersects(@coordinateRadius) = 1 )
order by b.GeoLocation.STDistance(@coordinatePoint) asc
END
I capture it in SQL Profiler and it shows the query and over 188 statements in a row, which is really confusing because when i run this in SSMS it just shows 1 execution, but running in application generates 188 sub-statements.: