DBNull error on upgrade

If you have questions about using mojoPortal, you can post them here.

You may want to first review our site administration documentation to see if your question is answered there.

This thread is closed to new posts. You must sign in to post in the forums.
1/23/2012 1:05:27 PM
Gravatar
Total Posts 73

DBNull error on upgrade

I'm using mojoPortal .NET 4 MSSQL v2.3.6.5 and am upgrading to latest 2.3.7.6.

I originally attempted performing the upgrade to 2.3.7.5, and ran the setup page with that version installed so the database was upgraded.

I had some trouble with the new skins I was trying to deploy, so I just switched the site back to the prior 2.3.6.5 version rather than fuss with it live.  I didn't think to roll the db back to the backup I made prior to the upgrade.

Now I'm trying to roll out 2.3.7.6 and upon trying to load any regular page, the site throws on object cannot be converted from DBNull exception.  If I go back to 2.3.6.5, it works fine.

I grabbed a copy of the database and have it on my development machine.  I'm trying various revisions of the code to see what works, but wanted to throw this question out there so maybe someone else has some better insight.  Saw lots of forum posts when I searched for DBNull but nothing that looked like it applied to my case.

Thanks.

Ted

1/23/2012 1:25:38 PM
Gravatar
Total Posts 18439

Re: DBNull error on upgrade

Can you post a stack trace so I can see where the error is happening?

1/23/2012 4:19:57 PM
Gravatar
Total Posts 73

Re: DBNull error on upgrade

Sorry for the lag in response.

Here's the error message in full:

Object cannot be cast from DBNull to other types.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Object cannot be cast from DBNull to other types.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidCastException: Object cannot be cast from DBNull to other types.]
System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider) +56
System.Convert.ToInt32(Object value) +28
mojoPortal.Business.WebHelpers.CacheHelper.LoadMenuPages() +2482
mojoPortal.Business.WebHelpers.CacheHelper.GetMenuPagesFromContext() +143
mojoPortal.Web.mojoSiteMapProvider.BuildSiteMap() +102
mojoPortal.Web.mojoSiteMapProvider.GetRootNodeCore() +15
System.Web.SiteMapProvider.get_RootNode() +15
mojoPortal.Web.layout.Page_Load(Object sender, EventArgs e) +318
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +46
System.Web.UI.Control.OnLoad(EventArgs e) +83
System.Web.UI.Control.LoadRecursive() +120
System.Web.UI.Control.LoadRecursive() +190
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3950

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

1/24/2012 8:53:48 AM
Gravatar
Total Posts 18439

Re: DBNull error on upgrade

Hi Ted,

My best guess is that somehow some of the update statements in the upgrade scripts did not get executed or did not work.

What I would do to solve this is look through each of the upgrade scripts form version 2.3.6.5 up to the newest for places where we added columns to tables and then updated those columns to not be null. I would manually run those fragments that update the new coulmns.

Scripts are located under /Setup/applications/mojoportal-core/SchemaUpgradeScripts/mssql

ie one example is in 2.3.6.7.config it has:

ALTER TABLE [dbo].mp_Pages ADD
PublishMode int NULL
GO

UPDATE mp_Pages
SET PublishMode = 0

GO

ALTER TABLE [dbo].mp_Modules ADD
PublishMode int NULL
GO

UPDATE mp_Modules
SET PublishMode = 0

GO

You might need to re-run the parts that update the columns like

UPDATE mp_Pages
SET PublishMode = 0
WHERE PublishMode IS NULL

I would look through each of the scripts for things like that and run them to ensure there are no null values.

Hope that helps,

Joe 

1/24/2012 9:27:25 AM
Gravatar
Total Posts 73

Re: DBNull error on upgrade

That's about what I was thinking.  How I wish I had restored my db after the aborted upgrade. :)

I'll stride through it and see what I can find.

Thanks.

1/27/2012 3:21:33 PM
Gravatar
Total Posts 73

Re: DBNull error on upgrade

So here's the resolution.

I believe the problem was indeed the fact that I didn't roll back the database.  This makes sense because in version 2.3.6.7, two columns were added and initialized to 0: mp_Pages PublishMode and mp_Modules PublishMode.

When I upgraded, they surely got initialized properly, but then I downgraded without backing out the schema changes, so further rows got added to the db which weren't aware of the new columns, leaving them null.  This ended up being a problem when the code was upgraded again and didn't allow for null values in the new columns.

The solution was to run the update statements for those two columns, setting all values to 0.  They were:

UPDATE mp_Pages
SET PublishMode = 0

GO

and:

UPDATE mp_Modules
SET PublishMode = 0

GO

On another note, the reason it took me so long to get back about this is because I was dealing with the significant changes in the html between 2.3.6.5 and 2.3.7.5.  Some of it has to do with Artisteer, but there was actually another very significant change that happened to affect my CSS selectors in particular.

I have some custom ways of placing content modules side-by-side in my layout by using floats and display: table-cells.  When I first looked at doing it, it seemed like the custom CSS class setting for the content module might do the trick.  I was sad to find out, however, that the div with the custom CSS was nested inside a couple other divs within each content module.  Since the custom CSS div levels for two content modules weren't at a sibling level, you couldn't use float or table-cell to connect them side-by-side.

So instead, I found that there were module id's at the proper level (#module100, etc) that I could use to control the layout the way I wanted.  While this resulted in painfully custom CSS tied to each and every module, there were few enough places which needed it that I could get away with doing so.  How I wished that I could have just used the custom CSS class setting in the first place.

The good news is that with 2.3.7.5, the enveloping divs around the custom CSS class div are gone, putting the proper div at sibling level with every other content module.  Great!

Unfortunately, all of the module id's are gone!  So all of my carefully crafted CSS falls flat on its face.  Ouch.  So I went through the exercise of figuring out the cause and migrating to custom CSS classes which apply floats and table-cells in the content module settings, and it works like a charm.  I'll write a post about how I do it at some point.

However, now I'm concerned that the current html structure may become impermanent as well, in case some of those nasty enclosing divs show up in a future release.

To be more precise, here is an example:

I add HTML content module A.  I add a custom CSS class "table-cell" to the module settings, which renders a div with the content inside and marked with the table-cell class.

In my CSS, I define .table-cell to be "display: table-cell".

I then add HTML content module B, appearing right after A.  I add the same custom CSS class to the module settings.  Now, another div with the content for module B renders with the table-cell class.

Because both content modules are divs with the table-cell class and appear next to each other (siblings) in the tree, all modern browsers with turn them into a row in an "anonymous table", i.e., a table that is created by the browser to imitate the layout of the full set of table, td and tr tags that you'd have to create in HTML otherwise.  It's just as if I'd put the content modules within two cells of a table so they could be displayed next to one another, except it requires no markup, just CSS.

Now, if the divs that get the custom CSS class were to move lower in the tree and no longer be siblings, my layout would be blown because table-cells only join when they are right next to each other.

What are the chances of that structure being changed again?  Was the custom CSS class setting moved to the outer div of the content module by design and will it stay there in future versions?

1/28/2012 6:30:33 AM
Gravatar
Total Posts 18439

Re: DBNull error on upgrade

Hi Ted,

As far as the div structure changes, I can't promise things will never change again but I don't think they will because the changes were done to make it more flexible. For details about the rationale, see the article A More Flexible Set of Container Panels. These panels can now have properties controlled from theme.skin so it is possible to do a lot of things that were not possible before, it was also part of the solution that made it possible to support different requirements for new versions of Artisteer where they keep changing the css classes while still supporting older versions as well. 

For each level of panel you can control what element it renders as (ie if you wanted to you could use newer html 5 elements), you can reduce the number of containers by configuring specific level to only render their contents and no div or element of their own, you can control what css classes are used, etc.

So my hope is that this is now flexible enough that we won't need to change it, ie if things change again in the next version of Artisteer hopefully it will only require changes in theme.skin.

Hope that helps,

Joe

1/30/2012 9:20:56 AM
Gravatar
Total Posts 73

Re: DBNull error on upgrade

Thanks much for the pointer to the article, I had missed that one.  Very informative.

The changes you made are great, in fact, in my latest skin designs I've been using the theme.skin changes to good effect to handle certain artisteer features.  I didn't even know they were in just the latest versions of mojoPortal.  I'm much happier when adapting some of the sample Artisteer skins from their website now that I know how to use theme.skin and with the top-level custom CSS classes.

Thanks!

You must sign in to post in the forums. This thread is closed to new posts.