After moving Database - [CMSAbstractTransformation.DataBind]: Object reference not set to an instanc

J Shaw asked on April 19, 2016 02:30

Hi all,

I have noticed an issue when I backup a database and restore to a different server, that custom fields on custom pagetypes do not remember custom properties. The next time I visit the site I see a number of broken controls that rely on custom data to populate. The only fix I can tell is to resave the affected page.

For example, I have a user control that displays 3 CTAS of document type CTA. It works great, and then I restore the database to a new server and receive the error: [CMSAbstractTransformation.DataBind]: Object reference not set to an instance of an object. If I go and remove the custom field from the transformation, then it will work again.

I can then go and re-save one of the CTAs and it will begin to work for that 1 CTA. I eventually have to go and re-save all custom pagetypes that this happens to.

I am pretty sure this has to do with the use of SELECT * in a lot of the Kentico views and stored procs. The stored procs/views have to be rebuilt since they get built and don't know about the new custom fields.

Any idea how I can fix this?

Thanks, John

Recent Answers


Brenden Kehren answered on April 19, 2016 04:25

When you're backing up and restoring are you selecting only specific items or are you doing a full restore of the database? I've done ONLY full restores and overwrites without an issue. If you're only doing partial or transnational restores, then you might want to rethink what you're doing.

0 votesVote for this answer Mark as a Correct answer

J Shaw answered on April 19, 2016 04:31

Thanks Brenden, It is a full backup and restore. Today I backed up my production database and restored to dev. When I pointed my dev codebase at the restored database is when I started having this problem. This is not the first time this has happened and Ive usually fixed by resaving, but not idea as site get larger.

Thanks, John

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on April 19, 2016 05:37

What version are you running?

0 votesVote for this answer Mark as a Correct answer

J Shaw answered on April 19, 2016 05:43

We are running version 8.2. I will be upgrading to 9 soon so maybe that will help. Thanks again for the help.

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on April 19, 2016 19:04

Hi,

I can think of two solutions as I believe I have faced this before.

  1. Check for syntax in the transformation. Could be the case that it's not compatible with new version. Less probability. However it used to happen a lot from 7 to 8.

  2. Goto database objects and click on button called refresh all your views and Go to system and restart server and check.

Cheers Chetan

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on April 19, 2016 19:05

Would you mind sharing the syntax of the transformation causing this problem?

0 votesVote for this answer Mark as a Correct answer

J Shaw answered on April 19, 2016 19:25

<cms:CMSRepeater ID="rptCTAs" runat="server"
Path="./%" SelectTopN="3" OrderBy="NodeLevel, NodeOrder, NodeName" ClassNames="xxx.CTA" TransformationName="xxx.CTA.Default" ShowEditButton="False" ShowDeleteButton="False" > </cms:CMSRepeater>

Transformation

<figure class="spans-33 call-to-action">
    <a href='<%# Eval("LinkUrl") %>' <%# Eval("LinkNewWindow").ToString() == "True" ? "target='_blank'" : "" %> >
    <img src='<%# Eval("Image") %>'>
  </a>
  <figcaption><%# Eval("Caption") %></figcaption>
</figure>
0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on April 19, 2016 19:35 (last edited on April 19, 2016 19:35)

I have a feeling that your column "LinkNewWindow" is null for some values and when are you are trying to call ToString() on it, it's throwing error.

Can you modify your code to use ifempty given here.

https://docs.kentico.com/plugins/servlet/mobile#content/view/37978601

1 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on April 20, 2016 14:17

I agree with Chetan, there is something with your syntax causing the problem.

Instead of this:

<%# Eval("LinkNewWindow").ToString() == "True" ? "target='_blank'" : "" %>

Try this:

<%# ValidationHelper.GetBoolean(Eval("LinkNewWindow"), false) == true ? "target='_blank'" : "" %>

The ValidationHelper class will attempt to get and convert that object's value to a boolean and return false if it cannot.

1 votesVote for this answer Mark as a Correct answer

J Shaw answered on April 20, 2016 18:44

Thanks, I will try this.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.