sivabudh
sivabudh

Reputation: 32635

Where did this invalid object name come from?

I have a simple SQL UPDATE query which is complaining about an "invalid object name" AuditCrudFields which doesn't exist in my ASP.NET project at all. (I have already tried grepping for AuditCrudFields in my project but couldn't find matches.)

The UPDATE statement is:

UPDATE [dbo].[PartModel]
SET partOfficial = 39, updateTS = CONVERT(DATETIME, ‘2017-12-08’, 111)  
WHERE partId = 298

the error returned:

enter image description here

What's puzzling is that these are all the properties that exist inside PartModel. So I wonder where did AuditCrudFields come from?

public class PartModel : EntityInformation
{
    [Key]
    public Int64 partId { get; set; }

    public int partTypeId { get; set; }
    [ForeignKey("partTypeId")]
    public virtual PartTypeModel PartType { get; set; }

    public int locationId { get; set; }
    [ForeignKey("locationId")]
    public virtual LocationModel Location { get; set; }

    public int partOfficial { get; set; }
    public int partUnofficial { get; set; }
    public int partThreshold { get; set; }

    public string partImg { get; set; }
    public int partStatus { get; set; }
}

Upvotes: 2

Views: 238

Answers (2)

Grantly
Grantly

Reputation: 2556

What you have is a deleted or renamed object called AuditCrudFields (I will call it a dead object)

This is probably inside a Trigger definition (or perhaps buried inside a Stored Procedure, Function or Index definition...)

The most effective way of finding a dead object is by scripting your entire database into text (into one big SQL Script), then search for the text...

Where you find the text, will point to where it is used (a Trigger perhaps), and then you can repair or remove the trigger and hopefully its fixed.

There is alot of help with scripting a SQL SERVER database on the internet or SO, but here is another link

Upvotes: 2

Yuck
Yuck

Reputation: 50825

You can run this query to locate the SQL object code which is trying to use the table AuditCrudFields:

select *
from sys.objects
where object_definition(object_id) like '%AuditCrudFields%'

I'd be very surprised if this is not inside a trigger definition.

Upvotes: 3

Related Questions