Invalid object name ‘UserInfo’

use ADO.NET Or other ORM framework, throw this exception, it may be the wrong database to connect. Maybe the database that the program wants to connect to is database1, and your configuration file or connection string is copied. If you neglect to modify it completely, this exception will appear.

Exception specific information

 NHibernate.Exceptions.GenericADOException : could not execute query
[ select userinfo0_.id as id0_, userinfo0_.name  as name2_0_, userinfo0_.description  as descript3_0_, userinfo0_.state  as state4_0_ from UserInfo userinfo0_ where userinfo0_.name ='testname' ]
[SQL: select userinfo0_.id as id0_, userinfo0_.name  as name2_0_, userinfo0_.description  as descript3_0_, userinfo0_.state  as state4_0_ from UserInfo userinfo0_ where userinfo0_.name ='testname']
  ----> System.Data.SqlClient.SqlException : Invalid object name 'UserInfo'.
	at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
	at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
	at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes)
	at NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters)
	at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters)
	at NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results)
	at NHibernate.Impl.SessionImpl.List(String query, QueryParameters queryParameters, IList results)
	at NHibernate.Impl.SessionImpl.List[T](String query, QueryParameters parameters)
	at NHibernate.Impl.QueryImpl.List[T]()
	UserInfoDAL.cs(21,0): at NHibernateWCF.DAL.UserInfoDAL.ExistUserInfo(String name)
	UserInfoDALTest.cs(18,0): at NHibernateWCF.Test.UserInfoDALTest.ExistUserInfoTest()
	--SqlException
	at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
	at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
	at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
	at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
	at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
	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)
	at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
	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.System.Data.IDbCommand.ExecuteReader()

This is the stack information in the case of NHibernate when the connection database is inconsistent. use ADO.NET Or other frameworks may be different in details, but they should all be exceptions of this kind in general.

The solution is to modify the connection string, change the database connected in the configuration to the correct database, so that the corresponding table can be found when executing SQL statements.

Read More: