【问题标题】:Invalid Object Name dbo.TableName even when such a table exists in the DB无效的对象名称 dbo.TableName 即使数据库中存在这样的表
【发布时间】:2015-02-19 14:45:05
【问题描述】:

在我的项目的其中一个环境中运行 Windows 服务时出现以下错误:

错误信息:

An error occurred while executing the command definition. See the inner exception for details.

内部异常消息:

Invalid object name 'dbo.ProcessTracker'.

堆栈跟踪:

 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, SqlDataReader ds)
   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.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext`1 c)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

我已确保服务连接到的数据库中存在这样的表。此外,相同的服务安装在其他环境/服务器中并且运行良好。

我们使用的是 EF 6 谁能帮我解决这个问题?

【问题讨论】:

  • 更多信息。我尝试从本地计算机连接到运行服务代码(它是顶级服务)的同一个数据库,并得到了同样的错误。但是,我使用相同的连接详细信息从 SSMS 登录到数据库,我发现该表存在于 dbo 下。架构。
  • 您确定服务正在连接到正确的数据库吗?
  • 这可能是一个愚蠢的问题,但我如何确保服务正在连接到数据库。它当然没有加载任何表,但如果它根本无法连接,它不会在初始化时抛出“无法连接”异常吗?
  • 你能显示你正在使用的连接字符串吗?您可以尝试停止服务器,如果应用仍然报告相同的错误,您就知道它没有尝试连接到正确的位置。
  • 这是暂存环境,UAT 的准备工作正在进行中。许多其他团队正在测试他们的组件。所以停止服务器超出了范围。我会尽快发布连接字符串。

标签: .net entity-framework c#-4.0 windows-services


【解决方案1】:

伙计们,

问题出在配置文件中的连接字符串上。导致此问题的配置文件中存在错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 2015-07-28
    • 1970-01-01
    • 2014-03-13
    • 1970-01-01
    相关资源
    最近更新 更多