Error "Invalid object name" during db.SaveChanges () (Entity Framework / MVC)

(allowed)

I am getting a really strange error when trying to save changes to an entity from the application we are creating.

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Edit([Bind(Include = "ReportID,RecordID,ReportName,FileName,ReportTypeID,OwningApplicationID,RecordCID,AssignedUserID")] Report report)
    {
        if (ModelState.IsValid)
        {
            db.Entry(report).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        ViewBag.OwningApplicationID = new SelectList(db.Applications, "ApplicationID", "ApplicationName", report.OwningApplicationID);
        ViewBag.ReportTypeID = new SelectList(db.ReportTypes, "ReportTypeID", "ReportTypeText", report.ReportTypeID);
        return View(report);
    }

      

In db.SaveChanges () I am getting the following error:

An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll but was not handled in user code

If I look at the internal exceptions I find this:

"Invalid object name 'tg_DataCleaningMaintenance_PendingInsert__20150709_000000_953cccd7-0ba4-4b3e-ae5d-df6b936841f8'."

The exception happens here:

at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut) at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult, Func'2 updateFunction) at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update() at System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35() at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func'1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction) at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass2a.<SaveChangesInternal>b__27()

I can't find anything online about DataCleaningMaintenance_PendingInsert or something similar. I remember that a week ago I saw a table with a similar name in the database. It has since been removed.

I updated my model from the database, rebuilt the project, looked at the project for any reference to this table, confirmed that the table does not exist in the database. I am looking at the db object while debugging and cannot find a reference to that object, and I have verified that the connection string is correct and includes the database name (not just the server name). I don't know how to approach this problem at the moment. Please, help!

Thank!

EDIT: There was indeed a trigger set in the reporting table on SQL Server that was causing the server to reject my update with the above message. The trigger seems to have come from the SSIS package that FuzzyLookup was using on this table. Removing the trigger should fix this problem.

+3


source to share


2 answers


Solved thanks to br4d!

The SQL Server reporting table has a trigger left over from the SSIS package that used FuzzyLookup on this table. I'm not sure how I missed this as I have definitely checked triggers in SSMS. I used this query to find it:

SELECT * FROM (
  SELECT OBJECT_NAME(OBJECT_ID) Obj,
  SCHEMA_NAME(schema_id) [Schema],
  OBJECT_NAME(parent_object_id) Parent,
  type_desc Obj_Type
  FROM sys.objects
) Objects
WHERE Obj LIKE 'tg_%'

      



Saw that it was a trigger in the report, double-checked the Triggers folder and lo and behold, here it is. He looked for the tg_DataCleaning_xxx table in INSERT, UPDATE and DELETE queries. Removed it and had no more problems.

There were no problems in my application code.

+1


source


You tried to navigate to your model, then Ctrl + A to select all tables / views / etc and then hit delete.

Then refresh the database again.



EF got a few random bugs because "updating from database" doesn't delete old objects that were deleted a long time ago!

Obviously, it might be worth making a backup first, although I've never had a problem using this technique.

0


source







All Articles