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

霸气de小男生 提交于 2020-06-12 04:57:17

问题


This is the error message returned:

Msg 208, Level 16, State 1, Line 1 Invalid object name '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',
'',
'',
'',
'',
'',
'',
'' )

回答1:


It means that it doesn't know what ENG_PREP is.

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

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:

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



回答2:


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.

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




回答3:


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

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




回答4:


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.




回答5:


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..



来源:https://stackoverflow.com/questions/3069356/how-to-solve-invalid-object-name-in-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!