none
bulk insert itaking too much in sharepoint 2010 RRS feed

  • Question

  • I have excel sheet of 15000 records

    I m inserting each record with some logic

    everytime i build xml of 2000 items and send it to server by below code..but there it stops execution until it creates all the 2000 records, i dont want to wait i want to continue with my another batch of 2000 records..

    now inserting it taking more than 45 min.. what to do?


    errorCode = spWeb.ProcessBatchData(insertbuilder.ToString());


    Guruprasad Marathe

    Wednesday, February 13, 2013 12:27 PM

Answers

  • Using ParameterizedThread in long operations, if you are inserting bulk records, web.ProcessbatchData takes longer time to complete and there code will stop execution until all items got created, so you can assign this to thread and continue your work

    private string InsertAllItemsBatch(StringBuilder insertbuilder, SPWeb spWeb)

           {

               ParameterizedThreadStart starter = new ParameterizedThreadStart(Start);

               new Thread(starter).Start(insertbuilder.ToString());

               return null;

           }

           static void Start(object insertbuilder)

           {

            //   StringBuilder insert = (StringBuilder) insertbuilder;

               string methodName = "InsertAllItemsBatch"; string errorCode = string.Empty;

               try

               {

                   SPSite site = new SPSite(PCDSConstants.PCDSSiteUrl);

                   SPWeb spWeb = site.OpenWeb();

                   if (spWeb.AllowUnsafeUpdates == false)

                       spWeb.AllowUnsafeUpdates = true;

                   errorCode = spWeb.ProcessBatchData(insertbuilder.ToString());

                   spWeb.AllowUnsafeUpdates = false;

                  // return errorCode;

               }

               catch (Exception ex)

               {

                   ExceptionHelper.HandleException("Error in " + methodName + ex.Message, ex.StackTrace);

                 //  return null;

               }

           }


    Guruprasad Marathe

    Tuesday, February 19, 2013 5:34 AM