Wednesday, January 14, 2015

Resolved: Save conflict!

I've got the headache for one week when I tried to add a new column into list by ListAdded event receiver. It was through the exception "Save conflict..." and I've tried many ways to fix this issue, but I failed.

{
   list.AddFieldAsXML("field_definition");
   list.Update();
 
   //Resolve here - re-fetch
   list = web.List["ListID"];
   SPField newF = ...
   newF.Title = "New Title";
   newF.Update();
}

I really stuck in the dark hole!

Resolve: Sometime, you should refresh your life by hanging out with your friend or buy a ticket for comedy show. For what? To clean all the troubles, problems and worries about the life. I've never thought about the FETCH until now that the list defninition in the database was changed. To update anything into list, just re-fetch the list! That's all. God save me life!

Gravo!

Wednesday, January 7, 2015

Error when add new item by programmatically: 0x80131904

I had never loved the error, especially with the unknown error. See this:

<nativehr>0x80131904</nativehr><nativestack></nativestack>

The message is not friendly and there is no key in my mind. The stack trace shows seem a bit more details:


at Microsoft.SharePoint.Library.SPRequestInternalClass.AddOrUpdateItem(String bstrUrl,
at Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, 
--- End of inner exception stack trace ---
at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
at Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl,
at Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, 
at Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem,
at Microsoft.SharePoint.SPListItem.Update()

Basically I just add new item by programmatically and it throw exception.

Solution: I found the reason and resolved this with my situation. In my list, there is a column that work incorrectly. I could not access the value of that column, eventhough I could get the details of its. I remove that column out of the list's schema and then re-add into list. It worked!