I imported 700+ news articles from the previous CMS, which i did programmatically without issue using "contentService.CreateContent(..." and "contentService.SaveAndPublishWithStatus(data);" I added a prefix so that there would not be any name clashes - however now I want to remove that prefix (e.g. "20171205-") on a "menuTitle" field that I use as the article title.
But there is a save problem after I have updated the value:
I have tried
"var c = Services.ContentService.GetById(x.Id);"
(x is the IPublishedContent of the page)
along with
"var saveAttempt = Services.ContentService.SaveAndPublishWithStatus(c);"
or even
"Services.ContentService.Save(c);"
but i just get this error
"Cannot insert the value NULL into column 'id', table 'UMBCinvenLocal.dbo.cmsContentVersion'; column does not allow nulls. INSERT fails.
The statement has been terminated."
foreach (var x in list) {
np = (NewsPage)x;
menutitle = np.MenuTitle;
if (menutitle.Length > 8) {
if (menutitle.Substring(6, 1) == "-") {
var c = Services.ContentService.GetById(x.Id);
sb.AppendLine("Success! ID: " + c.Id + " c.Name: " + c.Name);
c.SetValue("menuTitle", menutitle.Substring(7));
Services.ContentService.Save(c);
The stringbuilder still gives output - but the error is still there on the save:
Cannot insert the value NULL into column 'id', table 'UMBCinvenLocal.dbo.cmsContentVersion'; column does not allow nulls. INSERT fails.
The statement has been terminated.
Googling that error seems to suggest others have seen this error when they've either scripted and recreated the DB on a server (and missed the unique identifer auto increment property off that table) or manually inserted data straight into the db and botched it.
Update page property programmatically
I imported 700+ news articles from the previous CMS, which i did programmatically without issue using "contentService.CreateContent(..." and "contentService.SaveAndPublishWithStatus(data);" I added a prefix so that there would not be any name clashes - however now I want to remove that prefix (e.g. "20171205-") on a "menuTitle" field that I use as the article title.
But there is a save problem after I have updated the value:
I have tried
"var c = Services.ContentService.GetById(x.Id);" (x is the IPublishedContent of the page)
along with "var saveAttempt = Services.ContentService.SaveAndPublishWithStatus(c);"
or even "Services.ContentService.Save(c);"
but i just get this error
"Cannot insert the value NULL into column 'id', table 'UMBCinvenLocal.dbo.cmsContentVersion'; column does not allow nulls. INSERT fails. The statement has been terminated."
Does anyone know whatI am doing wrong here?
Thanks, Marshall
Are you sure that the x.Id is an actual content node ID?
Can you check for a null on c - are you debugging? Stick a breakpoint after you GetById and see if you are actually getting a content object back.
Hi Steve,
Yes i am sure that x.Id is the content node:
this is giving this output into the StringBuilder:
Success! ID: 1476 menuTitle: 170731-XXXXX completes Private Placement of XXXXX Success! ID: 1478 menuTitle: 170710-XXXXX invests in XXXXX, the leading XXXXX services provider Success! ID: 1479 menuTitle: 170629-XXXXX generates successful partial realisation of XXXXX Success! ID: 1480 menuTitle: 170628-XXXXX completes acquisition of XXXXX Success! ID: 1481 menuTitle: 170619-XXXXX extends relationship with XXXXX until 2021 Success! ID: 1483 menuTitle: 170523-XXXXX continues expansion in Europe with the acquisition of XXXXX
Do you think is might have something to do with the transition to the id that has the int plus the guid format?
Marshall
The stringbuilder still gives output - but the error is still there on the save:
Cannot insert the value NULL into column 'id', table 'UMBCinvenLocal.dbo.cmsContentVersion'; column does not allow nulls. INSERT fails. The statement has been terminated.
Googling that error seems to suggest others have seen this error when they've either scripted and recreated the DB on a server (and missed the unique identifer auto increment property off that table) or manually inserted data straight into the db and botched it.
I take it neither of those apply?
Are you running on SQL Express / SQL Server?
Check that table has the Identity Specification
Hi Steve,
I did indeed recreate the database from azure down locally via a .bacpac file - and that is indeed the problem.
What was wrong with the old Sql Server .bak file format? Force-restore and off you go!
So i can assume that all the tables need identity switched on then?
Marshall
I will re-download load it using Create Scripts and set it to Schema and Data
Thanks very much
Marshall
is working on a reply...