This error was caused by deleting the user that had created the blog.
The table Blog_Blogs contains a field UserID which is used in the stored procedure Blog_GetBlog. In my case UserID 7 was missing. I changed the UserID on the Blog_Blogs entry to a valid UserID and the problem was solved.
Is this a bug or design omission? I suspect it is a situation that will not arise very often.
<rant>
Perhaps rather than just throwing a blanket exception a message with some indication of the cause might help. This is one of my main complaints about DNN - exceptions logged without any real indication of the cause. Surely developers would not get away with this in their own work. At a minimum an error message should indicate where the error occurred and some inidcation of what the application was attempting to do at the time.
This is just a cop-out and often useless:
Catch exc As Exception
ProcessModuleLoadException(Me, exc)
A little more is needed to tell us where the error occurred and why.
In this instance the error states that "Value cannot be null". This is correct as the usertable joined in the stored procedure will return null for the requested user because the row has been deleted.
Rather than catching the exception in page load, having filtered back up from the call to the db, why not log the exception earlier with a little helpful information.
Instead of (which we se everywhere!):
Public Overrides Function GetBlogByUserID(ByVal PortalID As Integer, ByVal UserID As Integer) As IDataReader
Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "Blog_GetBlogByUserID", PortalID, UserID), IDataReader)
End Function
Would something like this be better:
Public Overrides Function GetBlogByUserID(ByVal PortalID As Integer, ByVal UserID As Integer) As IDataReader
Dim idr As IDatareader
Try
idr = CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "Blog_GetBlogByUserID", PortalID, UserID), IDataReader)
If idr Is Nothing Then
' Personally I use log4net to log messages in debug situations.
' available free here: logging.apache.org/log4net/index.html
log.Debug(String.format("Blog:GetBlogUserByID: Portal {0}, UserID {1}", PortalID, UserID))
End If
Catch ex As Exception
log.Debug(String.format("Blog:GetBlogUserByID: Portal {0}, UserID {1}", PortalID, UserID))
End Try
Return idr
End Function
At lease we would know where something happened and a little about why.
</rant>
Rather than just rant I am prepared to assist in adding such error handling to DNN code, if such help is desired. Perhaps others have better ideas. If so I would like to hear them. Many of the posts in the DNN forums are seeking help on errors from the Event Log such as the one I posted above.
I am unable to add this to the Blog project on Gemini.
Declan