How to solve the problem of "invalid SQL object name"

Source: Internet
Author: User

Today, I encountered an uncertain problem.

After the website is upgraded, a page cannot be accessed, and the message "Object Name" xxx "is invalid.

The xxx table is not created on the server, so you can open "SQL query analyzer ":

Export the SQL script for creating the xxx table as follows:

 
 
  1. CREATE TABLE [xxx] (  
  2. [id] [int] IDENTITY (1, 1) NOT NULL ,  
  3. [title] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,  
  4. [kind] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,  
  5. [content] [nvarchar] (1000) COLLATE Chinese_PRC_CI_AS NOT NULL ,  
  6. [keyword] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,  
  7. [Add_Date] [datetime] NULL 
  8. ) ON [PRIMARY] 

Create a new one on the server and refresh it again. The prompt is: the object name "xxx" is invalid. You can pull bananas ~~

The possible cause for searching on Google is the database owner problem. The database may have different login accounts,

The database can belong to an account, so the problem arises.

If you log on to the logina account in the pubs database and create an x table, then log on to the loginb account and query the x table

The error message "xxx" is invalid.

Let me go !~

N

The ghost knows that the script just created the table to that user. So, I opened "Enterprise Manager" again ",

Select the table to export the SQL script. The script generated this time includes the owner:

 
 
  1. CREATE TABLE [logina].[xxx] (  
  2. [id] [int] IDENTITY (1, 1) NOT NULL ,  
  3. [title] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,  
  4. [kind] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,  
  5. [content] [nvarchar] (1000) COLLATE Chinese_PRC_CI_AS NOT NULL ,  
  6. [keyword] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,  
  7. [Add_Date] [datetime] NULL 
  8. ) ON [PRIMARY]  
  9. GO 

So I dropped the xxx table on the table server and ran the above script.

Refresh again, Niang SIPI! Or: the object name "xxx" is invalid.

My database access layer uses subsonic, so I read the code generated by subsonic and found that

One row:

 
 
  1. schema.SchemaName = @"dbo"; 

Wow! But the login name in the database connection string is not like this!

However, other tables seem to have no query problems ??????????????????????????????

Therefore, I added the following line to the code running on the server:

 
 
  1. output q.BuildSqlStatement(); 

You directly run the generated query code on the server, and the prompt is: the object name "xxx" is invalid.

My day ~!

In the generated script, the owner added before the xxx table is "dbo ~

Again, drop table xxx, and then:

 
 
  1. CREATE TABLE [dbo].[xxx] (  
  2. [id] [int] IDENTITY (1, 1) NOT NULL ,  
  3. [title] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,  
  4. [kind] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,  
  5. [content] [nvarchar] (1000) COLLATE Chinese_PRC_CI_AS NOT NULL ,  
  6. [keyword] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,  
  7. [Add_Date] [datetime] NULL 
  8. ) ON [PRIMARY]  
  9. GO 

Refresh again. The cute girl is still shy .~~~

Summary:

1. Pay attention to the table owner issue in a real production environment.

2. Tables created by different owners cannot be accessed when other users log on. A message is displayed, indicating that the object name "xxx" is invalid.

3. Why does my login name be logina, but when logina is added, the system prompts that the object name "xxx" is invalid? Because subsonic

The generated script uses dbo. Why? Ghost knows ~~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.