I have a program that fails intermittently in a complex query. The error reads: System.Data.SqlClient.SqlException: Cannot fetch a row from OLE DB provider "MSDASQL" for linked server "LinkedServer". The query looks like this: SELECT Replace([JOB-NO],'M0','') as KeyTaskID, dbo.SFGET_UniqueTaskID([CLIENT-CODE],Replace([JOB-NO], 'M0', ''), 0, [TRADE-CODE]) AS HMSUniqueTaskID, [LATEST-PRIORITY] AS PriorityCode, [KeyProperty] AS KeyProperty, Replace([JOB-NO],'M0','') AS KeyJob, [JOB-TYPE] as TaskSubType, CONVERT(varchar(6),[MAINT-OFFICER]) AS Officer, LEFT(FORENAME + ' ' + SURNAME, 50) AS OfficerName, [JOB-NO] + ' ' + LEFT(RTRIM(REPLACE([TEXT-LINE], ';', CHAR(13))), 480) AS Description, dbo.SFGET_FormattedDate([TARGET-DATE],0) AS DueDateTime, [CURRENT-STAGE-CODE] AS CurrentStageCode FROM openquery(LinkedServer, ' SELECT DISTINCT "RM-JOB"."JOB-NO", "RM-JOB"."CLIENT-CODE", "RM-JOB"."LATEST-PRIORITY", "RM-JOB"."TRADE-CODE", "RM-JOB"."JOB-TYPE", "RM-JOB"."TARGET-DATE", "RM-JOB"."MAINT-OFFICER", "RM-JOB"."TEXT-LINE", "RM-JOB"."CURRENT-STAGE-CODE", "RM-JOB"."PLACE-REF", "IH_OFFICER".FORENAME, "IH_OFFICER".SURNAME FROM "PUB"."RM-JOB" LEFT OUTER JOIN "PUB"."IH_OFFICER" ON ("IH_OFFICER"."OFFICER-CODE" = "RM-JOB"."MAINT-OFFICER") WHERE "RM-JOB"."JOB-TYPE" = ''GASS'' AND "RM-JOB"."JOB-STATUS" = 06 AND "RM-JOB"."CONTRACTOR" = ''NWH001'' ') as ibsTasks INNER JOIN [SVSExtract].[dbo].Property prop ON ibsTasks.[PLACE-REF] = prop.UserCode I have been testing it manually using SQL Server Management Studio. It occassionally fails but it mainly works OK. I am at a loss as to how I can debug an error that I cannot reproduce at will. Any suggestions? Continue reading...