Hello all,
please help i m receiving below error "An existing connection was forcibly closed by the remote host" ocasionally. Mostly inacase of Large items
My code is as below:
- public ListItemCollection GetListItemCollection(ref int p_startOffset, ref int p_endOffset,
- SPClientList _list, ClientContext p_ClientContext,
- ref int p_retry)
- {
- CamlQuery f_caml = null;
- ListItemCollection f_ListItems = null;
-
- try
- {
- try
- {
- if (p_ClientContext.HasPendingRequest)
- p_ClientContext.ExecuteQuery();
- }
- catch (Exception)
- {
- }
- if (COMMON.StopProcess || COMMON.m_LastErrorCode == LastErrorCode.NetworkNotAvaliable ||
- COMMON.m_LastErrorCode == LastErrorCode.NetConnectionDisconnected)
- return null;
- f_caml = new CamlQuery();
-
- if (p_startOffset == 1)
- {
- f_caml = CamlQuery.CreateAllItemsQuery(p_endOffset);
- }
- else
- f_caml.ViewXml = "" +
- "" + p_startOffset +
- "" +
- "" +
- "" + p_endOffset +
- ""
- + "" +
- "";
- f_ListItems = _list.GetItems(f_caml);
-
- p_ClientContext.Load(f_ListItems);
-
- p_ClientContext.Load(f_ListItems, items => items.Include
- (
-
- item => item.DisplayName,
- item => item.ContentType,
- item => item.Id,
- item => item.FieldValuesAsText,
- item => item.Folder,
- item => item.Folder.ServerRelativeUrl,
- item => item.FieldValuesAsHtml,
-
- item => item.Versions,
- item => item.Versions.Include(
- ver => ver.VersionId,
- ver => ver.VersionLabel,
- ver => ver.Fields,
- ver => ver.Created,
- ver => ver.CreatedBy,
- ver => ver.CreatedBy.Email),
- item => item.File,
- item => item.File.Versions,
- item => item.File.MinorVersion,
- item => item.File.MajorVersion,
- item => item.File.CheckedOutByUser,
- item => item.File.CheckedOutByUser.Email,
- item => item.File.CheckInComment,
- item => item.File.Versions.Include(
- ver => ver.CheckInComment,
- ver => ver.ID,
- ver => ver.Length,
- ver => ver.Url,
- ver => ver.VersionLabel,
- ver => ver.Created,
- ver => ver.CreatedBy,
- ver => ver.CreatedBy.Email),
-
- item => item.AttachmentFiles,
- item => item.AttachmentFiles.Include(
- attach => attach.FileName,
- attach => attach.FileNameAsPath,
- attach => attach.ServerRelativePath,
- attach => attach.ServerRelativeUrl),
-
- item => item.RoleAssignments,
- item => item.RoleAssignments.Include
- (a => a.RoleDefinitionBindings,
- a => a.PrincipalId,
- a => a.Member,
- a => a.Member.Id,
- a => a.Member.Title,
- a => a.Member.LoginName)));
- p_ClientContext.ExecuteQuery();
- if (p_startOffset == 1)
- {
- int f_Count = f_ListItems.Count - 1;
- p_startOffset = f_ListItems[0].Id;
- p_endOffset = f_ListItems[f_Count].Id;
- }
- }
- catch (Exception ex1)
- {
- COMMON.ExLogger.LogError(ClassName, "GetListItemCollection", ex1);
- if (!m_ObjChkConnection.InternetConnectionCheck())
- {
- COMMON.m_LastErrorCode = LastErrorCode.NetworkNotAvaliable;
- return null;
- }
- if (p_retry < 3)
- {
- Thread.Sleep(1000);
- p_retry++;
- COMMON.ExLogger.LogError(ClassName, "GetListItemCollection", "Retry = " + p_retry +
- " StartOffset = " + p_startOffset + " Endoffset = " + p_endOffset);
- f_ListItems = GetListItemCollection(ref p_startOffset, ref p_endOffset, _list, p_ClientContext,
- ref p_retry);
- }
- }
- f_caml = null;
- return f_ListItems;
- }