none
Strongly Named DataSet.AcceptChanges() problem (high cpu and runs for ever) RRS feed

  • Question

  • Hi,

    I am having problem with a dataset which in some cases will take up to 15 min to complete an AcceptChange and CPU usage is very high.

    I have tested a few things to see if I can make it go faster and I did make it much faster but I am not sure if it will have a side affect so that I cannot rely on the dataset.

    In my dataset I have one table that always will have changes lets call it Solutions.

    The implementation would looks like this.

    internal static void AcceptChanges(DataSet dataSet) { if (dataSet.HasChanges()) { if (dataSet.Solutions.GetChanges() != null) { dataSet.Solutions.AcceptChanges(); } for(int i = 0; dataSet.HasChanges() == true && i < dataSet.Tables.Count; i++) { if (dataSet.Tables[i].GetChanges() != null) { dataSet.Tables[i].AcceptChanges(); } } } }

    The reason for this way of doing it is that when AcceptChanges is called on a DataTable it will copy all rows changed or not into an array and I am guessing that this could be my problem. Also the cascading update/delete might have an effect on the issue (But I am not sure about this).

    So my question is: Will this work???

    Tuesday, April 8, 2014 3:42 PM

Answers

  • Hi Jensen,

    > So my question is still can I rely on the data and its state in the dataset after I have called my own way of accepting changes.

    When AcceptChanges is called, any DataRow object still in edit mode successfully ends its edits. The DataRowState also changes: all Added and Modified rows become Unchanged, and Deleted rows are removed. The AcceptChanges method is generally called on a DataTable after you attempt to update the DataSet using the DbDataAdapter.Update method. See them on http://msdn.microsoft.com/en-us/library/system.data.datatable.acceptchanges.aspx.

    If you want to use your own method to instead of AcceptChange method, you just need to change the DataRowState to unchanged by yourself.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 15, 2014 5:22 AM
    Moderator

All replies

  • Hi Jensen,

    >The reason for this way of doing it is that when AcceptChanges is called on a DataTable it will copy all rows changed or not into an array and I am guessing that this could be my problem. Also the cascading update/delete might have an effect on the issue (But I am not sure about this).

    You have found the root cause. If you DataTable has large data, AcceptChanges method causes poor performance. Use Sql Profiler to see the executed sql statements. For details refer to http://technet.microsoft.com/en-us/library/aa173918(v=sql.80).aspx.

    I assume you want to save changes into Sql Server. From Sql Server 2008, we can use table-valued parameter to submit changes into db. I recommend you have a try.

    http://msdn.microsoft.com/en-us/library/bb675163(v=vs.110).aspx

    http://www.codeproject.com/Articles/39161/C-and-Table-Value-Parameters.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, April 9, 2014 6:41 AM
    Moderator
  • Hi,

    Thanks for you reply.

    The data is not updated through the dataset so no add update or delete is done in the db when AcceptChanges is called. The changes to the db is done outside the dataset. I am looking at a large dataset with few changes so that is why I found calling AcceptChanges on the dataset to have too much overhead since it calls AcceptChanges on all tables in the dataset even if they have no changes.

    So my question is still can I rely on the data and its state in the dataset after I have called my own way of accepting changes.

    Regards,

    Paw

    Wednesday, April 9, 2014 7:07 AM
  • Hi Jensen,

    > So my question is still can I rely on the data and its state in the dataset after I have called my own way of accepting changes.

    When AcceptChanges is called, any DataRow object still in edit mode successfully ends its edits. The DataRowState also changes: all Added and Modified rows become Unchanged, and Deleted rows are removed. The AcceptChanges method is generally called on a DataTable after you attempt to update the DataSet using the DbDataAdapter.Update method. See them on http://msdn.microsoft.com/en-us/library/system.data.datatable.acceptchanges.aspx.

    If you want to use your own method to instead of AcceptChange method, you just need to change the DataRowState to unchanged by yourself.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 15, 2014 5:22 AM
    Moderator
  • Thanks!

    Regards

    Paw

    Tuesday, April 15, 2014 5:25 AM