简体   繁体   English

这个无效的对象名称从何而来?

[英]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. 我有一个简单的SQL UPDATE查询,抱怨“ ASP.NET项目中根本不存在”无效的对象名” AuditCrudFields (I have already tried grepping for AuditCrudFields in my project but couldn't find matches.) (我已经在我的项目中尝试了对AuditCrudFields进行AuditCrudFields ,但找不到匹配项。)

The UPDATE statement is: UPDATE语句是:

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

the error returned: 返回的错误:

在此处输入图片说明

What's puzzling is that these are all the properties that exist inside PartModel . 令人费解的是,这些都是PartModel内部存在的所有属性。 So I wonder where did AuditCrudFields come from? 所以我想知道AuditCrudFields来自哪里?

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; }
}

You can run this query to locate the SQL object code which is trying to use the table AuditCrudFields : 您可以运行此查询来查找尝试使用表AuditCrudFields的SQL对象代码:

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

I'd be very surprised if this is not inside a trigger definition. 如果这不在触发器定义内,我会感到非常惊讶。

What you have is a deleted or renamed object called AuditCrudFields (I will call it a dead object) 您拥有的是一个删除或重命名的对象,称为AuditCrudFields (我将其称为AuditCrudFields对象)

This is probably inside a Trigger definition (or perhaps buried inside a Stored Procedure, Function or Index definition...) 这可能在Trigger定义内(或可能埋在存储过程,函数或索引定义内...)

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... 查找失效对象的最有效方法是将整个数据库脚本化为文本(成一个大的SQL脚本),然后搜索文本...

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 还有就是帮助很多与互联网或等脚本SQL Server数据库,但这里是另一个链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM