Knowledge Essentials - 3Essentials Hosting

ERROR: "Invalid object name"

Article ID: 386

 Back to Search

Symptom:

 You receive "Invalid object name" when attempting to execute a SQL query or add a new database user to your MSSQL database.

Resolution:

This typically means 1 of 2 things... you've referenced an object (table, trigger, stored procedure,etc) that doesn't actually exist (i.e., you executed a query to update a table, and that table doesn't exist).  Or, the table exists, but you didn't reference it correctly... here's more detail on that...

MSDN says: "In SQL Server 2000, database users and schemas are implicitly connected. Every database user is the owner of a schema that has the same name as the user. In SQL Server 2005, schemas exist independently of the database user that creates them". That is why you have to explicitly specify schema name in TableName property if you use SQL Server 2005. For example, rather than "tableCustomers" you specify "admin.tableCustomers" where "admin" is schema name in which table "tableCustomers" was created.

If you specify just "tableCustomers", then dbo.TableCustomers is assumed... but if your tableCustomers was created in schema "admin", then you need to specify by the name "admin.tableCustomers".

This can show up not ONLY when executing SQL statements, but may even affect you when adding a db user... here's a scenario observed recently:

When trying to add a new DB user for a customer, we received the error "Invalid Object Name: SecurityLog".  The customer had a table named "SecurityLog" created in schema "service".  But why was it causing an error when we tried to add a db user?  Because the customer ALSO had a Trigger... and in the trigger was SQL referring to the table as "SecurityLog", not "service.SecurityLog".  And apparently, during DB user creation, MSSQL 2005 checks through all of this BEFORE it allows the user to be created.  The solution was to work with the  customer to address the improper reference to the table in the trigger, by either modifying the trigger, or deleting it so the customer could readd the trigger with the proper table reference.

The lesson learned from this?  If you're getting this error about an object in your database, and you're not sure what's generating it, you need to check ALL objects in your database (stored procedures, triggers, etc) to see if you haven't given a complete name for another object (i.e., schema.objectname).

 
Downloads Associated With This Article
No downloads are currently associated with this article.