This project is read-only.

Error Saving Item to the N2 Database

Topics: Developer Forum, Project Management Forum, User Forum
Mar 6, 2009 at 3:42 PM
I am starting to frequently see this sort of error on the N2 tables when saving to the database.
Could not insert: [N2.Details.DetailCollection][SQL: INSERT INTO n2DetailCollection (ItemID, Name) VALUES (?, ?); select SCOPE_IDENTITY()]
I have seen this before but it hasn't been very prevelant until I updated the N2 version to 1.4.4 last week. I haven't exactly narrowed down what is causing it, but I think it might have to do with the published, expires, and updated fields. Just a heads up for anyone who also might run into this, there is a quick fix. Just run this query on your database:

DBCC CHECKIDENT ( 'n2item' )
DBCC CHECKIDENT ( 'n2Detail' )
DBCC CHECKIDENT ( 'n2DetailCollection' )
DBCC CHECKIDENT ( 'n2AllowedRole' )

If I find more information on this, I will post it here.

Thanks
Daniel
Mar 6, 2009 at 6:38 PM
I am not sure if this is related, but I think it is.

What I have is a ContentItem with an EditableChildren attribute. Whenever I modify or save a child using the EditableChildren control it appears to create bad data in the database.

This is what I have seen.

When I click to edit a ContentItem added using the EditableChildren control in the navigation pane the Edit interface tells me "There is a newer version of this item that hasn't been published. Edit the newer version." Before clicking this link to edit the newer version I look at the Info in the top right hand of the screen and these are the statistics on the ContentItem

ID 491
Type Sidebar
Published 3/4/2009 10:02:45 AM

I then click on the link to edit the newer version and the Edit Interface tells me "This is a version of another item that is currently published. Edit the currently published version." The info at the top right hand of the screen lists the statistics of the ContentItem as 

ID 892
Type Sidebar
Published 3/4/2009 10:02:45 AM
Expired 3/6/2009 10:01:17 AM

I dont understand why the ContentItem has a published date.

I believe this weird data is causing some issues with the indexes and they are getting out of sync. So I believe if the issue was fixed with the EditableChildren attribute it might make this database issue less prevolent.

Thanks
Daniel
Mar 6, 2009 at 11:48 PM
Hi, you could turn on some logging to gain more insights into this:
  • Error email (n2/engine/error section in web.config)
  • Configure .NET trace listener
  • Set up log4net logging
  • Use sql server profiler
It looks like the problem could be related to detail collections. While I don't know what it is, a culprit in the past has been the link tracker. Are there any internal links to pages or documents when the errors occurs?
Mar 11, 2009 at 4:37 AM

Hello,

I got basically the same problem.

I'm using MySQL with the latest version from 8. of December:

I'm testing the Template project. adding new items no problem. However, as soon as I try to edit an existing item (e.g. PlainContentPage) I get the error.
<o:p></o:p>

public virtual ContentItem SaveVersion(ContentItem item)
{
CancellableItemEventArgs args = new CancellableItemEventArgs(item);
if (ItemSavingVersion != null)
ItemSavingVersion.Invoke(this, args);<o:p></o:p>

if (!args.Cancel)
{
    item = args.AffectedItem;
    ContentItem oldVersion = item.Clone(false);
    oldVersion.Expires = Utility.CurrentTime().AddSeconds(-1);
    oldVersion.Updated = Utility.CurrentTime().AddSeconds(-1);
    oldVersion.Parent = null;
    oldVersion.VersionOf = item;<o:p></o:p>

        if (item.Parent != null)
            oldVersion["ParentID"] = item.Parent.ID;
        itemRepository.SaveOrUpdate(oldVersion);    <---- Here it fails since the old version exists giving me errors such as Foreign Key constraints violations. It seems the code tries to replace the identity of the item, and this causes an exception. 
        if (ItemSavedVersion != null)
        ItemSavedVersion.Invoke(this, new ItemEventArgs(oldVersion));
    return oldVersion;
}
return null;
}

Steps to repro
1. Setup template project
2. Add plain content page
3. save and publish
4. select same page and click edit.
5. save text --> bang! Detailscollection already contains the item (caught exceptions in Nhibernate and it complained about FKEY violations)<o:p></o:p>

<o:p> Thanks
Gunnar
</o:p>

Mar 11, 2009 at 10:45 PM
In the past I've looked into some issues related to multiple transactions when using mysql. I'll try to reproduce the issue.
Mar 11, 2009 at 10:53 PM
Hi, 

Just to follow up. I couldn't get the behavior I wanted with the EditableChildrenAttribute. I ended up just adding the items I needed to add to Zones. That is a much easier implementation, although not as intuitive. So I have done very little research to follow up on this.

One other thing I found weird is when you save one item in the EditableChildrenAttribute it saves a new version of every child listed. Whenever I would make a simple change to any child item, I would see the database had a new version of every child item. This didn't necessarily cause any issues, but I dont understand why this is the case.

Thanks
Daniel
Aug 27, 2009 at 2:48 PM

Hi,

I've just posted to the Issue Tracker (#24464) an issue that I think is related to the issue described above. I have detailed a proposed work around. Hope this helps

James