locked
Database Error on Individual Post Pages Only RRS feed

  • Question

  • User-939035612 posted

    I just uploaded my site and noticed that I get an error from the database that leaves me with no idea what the cause is. It only happens on details pages for individual posts. Every other page on the site that displays data from the database is just fine. This is the error"

    A database operation failed while processing the request.
    AggregateException: One or more errors occurred. (Data is Null. This method or property cannot be called on Null values.)
    SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
    There are pending model changes for ApplicationDbContext
    In Visual Studio, use the Package Manager Console to scaffold a new migration for these changes and apply them to the database:
    
    PM> Add-Migration [migration name]
    PM> Update-Database
    Alternatively, you can scaffold a new migration and apply it from a command prompt at your project directory:
    
    > dotnet ef migrations add [migration name]
    > dotnet ef database update
    I have no clue what caused this. If the problem is with the DB then why does every other page work just fine?
    How do I find out which " method or property cannot be called on Null values" ????
    Monday, November 2, 2020 7:36 AM

Answers

  • User-939035612 posted

    Turned out there was just one entry in one table that had a null value. It was a nullable column, but required by the EF model. It's SQL Server data type is money, so somehow the null value broke a task that would get every entry from that table and then select one based on a key value. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 3, 2020 3:48 AM

All replies

  • User1120430333 posted

    I can tell you that you are trying to persist an EF entity/object to the database that has a null valued property, MS SQL Server database table column is not accepting null data for a column to be saved to the table and MS SQL Server is throwing an exception.

    1) configure the table column in the database to accept null data

    2) or debug your program and find out how a null value is populating a property in the EE entity/object that is being persisted to the database table

    Your other error is about migrations that I avoid like the plague. I use traditional DBA tools for migrations not EF. :)

     

    Monday, November 2, 2020 9:22 AM
  • User-939035612 posted

    Thanks, I've narrowed it down to just posts of a specific category and that category has a table with unique values, so it must have something to do with that. I seem to recall making a certain column optional that had been required, so that is probably it. That or maybe I am trying to get a nullable data type as non-nullable type.

    Tuesday, November 3, 2020 12:32 AM
  • User-939035612 posted

    Turned out there was just one entry in one table that had a null value. It was a nullable column, but required by the EF model. It's SQL Server data type is money, so somehow the null value broke a task that would get every entry from that table and then select one based on a key value. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 3, 2020 3:48 AM