如何解决 SQL Server 中的“无效对象名称”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3069356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 06:35:56  来源:igfitidea点击:

How to solve 'invalid object name' in SQL Server?

sqlsql-server-2005

提问by Penguen

This is the error message returned:

这是返回的错误消息:

Msg 208, Level 16, State 1, Line 1 Invalid object name 'ENG_PREP'.

消息 208,级别 16,状态 1,第 1 行 无效的对象名称“ENG_PREP”。

It happens after I try the following query:

它发生在我尝试以下查询之后:

insert into ENG_PREP VALUES('572012-01-1,572012-01-2,572012-01-3,572013-01-1,572013-01-2',
'',
'500',
'',
'A320 P.001-A',
'Removal of the LH Wing Safety Rope',
'',
'',
'',
'0',
'',
'AF',
'12-00-00-081-001',
'',
'',
'',
'',
'',
'',
'' )

回答by dcp

It means that it doesn't know what ENG_PREPis.

这意味着它不知道是什么ENG_PREP

You need to use a 'use xxx'(where xxx is the database name where the ENG_PREPlives) command first to tell it what database you are using. And once you do that, you need to make sure that ENG_PREPis present in that database.

您需要首先使用'use xxx'(其中 xxx 是所在的数据库名称ENG_PREP)命令来告诉它您正在使用什么数据库。一旦你这样做了,你需要确保它ENG_PREP存在于该数据库中。

If you're using .Net to connect, you need to make sure you specify the initial catalog so it knows what database to use, here's an example excerpt from a web.config:

如果您使用 .Net 进行连接,则需要确保指定初始目录,以便它知道要使用的数据库,以下是摘录自 a 的示例web.config

<add name="SqlConnection" connectionString="Data Source=(local)\SQLEXPRESS;Initial Catalog=your_db_name_here;Integrated Security=True"
     providerName="System.Data.SqlClient" />

回答by SEFL

It doesn't necessarily mean that it can't find "ENG_PREP" in your SQL insert query itself. Check any triggers that run on that table as well and make sure all of them have the exact table name spelled correctly.

这并不一定意味着它在您的 SQL 插入查询本身中找不到“ENG_PREP”。还要检查在该表上运行的所有触发器,并确保所有触发器的表名拼写正确。

This JUST happened to me when debugging a stored procedure and it took me half an hour to find it.

这只是在调试存储过程时发生在我身上,我花了半个小时才找到它。

回答by Ralf de Kleine

I means the table ENG_PREP doesn't exist in the connection you are using.

我的意思是表 ENG_PREP 在您使用的连接中不存在。

Check if you are connected to the right server/database. Also check the table name.

检查您是否连接到正确的服务器/数据库。还要检查表名。

回答by Hans Olsson

Sounds like it can't find the table.

听起来它找不到表。

Check that you're connected to the correct database.
That the table exists and that it's the correct spelling.

检查您是否已连接到正确的数据库。
该表存在且拼写正确。

回答by Sabareeshwari Kannan

I too faced this error in plain text query.. In my web application, i have used three connection string.. i had specified that query with particular DB Name and Table name.. My error get solved.. Hope it may useful for someone..

我在纯文本查询中也遇到了这个错误..在我的网络应用程序中,我使用了三个连接字符串..我已经用特定的数据库名称和表名称指定了该查询..我的错误得到解决..希望它对某人有用..