none
Invalid Object name error. RRS feed

  • Question

  • I have recently added a new table to my database then added the table to my EF datamodel. 

    When I do a basic query I get a invalid object error. The mapping is correct. Can anyone point me in the right direction to solve this issue. I can retrieve data from other tables.

    The query 

    FormCategory x = (from fc in dbContext.FormCategory
                                         select fc).First();

    The error message.

    Invalid object name 'dbo.FormCategory'.

    My colleague and I have tried the following to diagnose the issue. 

    Delete and re add entity to data model. 

    Delete table from database and re add entity to data model. 

    Reset VS2012

    Reset computer. 

    Add a new simple table to the database, add to data model. This table had the same issue as well.

    I am at a lost as to what could be causing this issue.

    The stack trace

       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
       at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
       at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
       at System.Data.SqlClient.SqlDataReader.get_MetaData()
       at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
       at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
       at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
       at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

    Tuesday, November 19, 2013 5:21 AM

Answers

  • Hello SomeGuyOnAComputer,

    Being strange for that. It should be a general operation.

    As far as I know, exception message ‘Invalid object name dbo.XXX’ means that EF is translating the LINQ query into a sql statement that uses an object (most likely a table) named dbo. XXX, which does not exist in the database.

    Please check your database and verify whether that table exists, or that we may be using a different table name.

    To check the created sql statement, we can do operations like below:

    1. Remove the First() method, let the query be lazy query.
    2. Debug the query and after running the query, then copy the created sql statement like below:

      3.Execute the sql statement in database directly to see whether it will throw error

    If this does not work for you, please have a try to run the program on the other PC with the same environment to check whether the VS or the entity framework has broken.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, November 20, 2013 2:07 AM
    Moderator