gpt4 book ai didi

c# - 仅在 Azure 计算模拟器中出现 EdmMetadata 错误

转载 作者:行者123 更新时间:2023-12-03 03:19:22 25 4
gpt4 key购买 nike

我无法让我的应用程序在 Azure 计算模拟器中运行。我使用的是 Entity Framework 6.0-pre2,当我的应用程序运行时,出现以下错误:

Invalid object name dbo.EdmMetadata

数据库是通过 Code First 迁移创建的。使用相同的连接信息,如果它在常规控制台应用程序或 ASP.NET MVC 4 网站内运行,则一切正常。

相关 app.config 部分:

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=localhost;Initial Catalog=Database;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>

我已验证 DbContext 使用正确的连接字符串

string connection = db.Database.Connection.ConnectionString;

仅当我在模拟器中启动任务(以及部署到 Azure 时)时才会发生这种情况,这是否有原因?

外部异常堆栈跟踪:

at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)

内部异常堆栈跟踪:

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.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

最佳答案

发生这种情况是因为 EF 正在检查数据库中是否存在 EdmMetadata 表以用于升级/向后兼容方案。然而,该异常由 EF 处理,因此除非您打开了“引发异常时中断”选项,否则您不应该看到它。启用此选项后,任何异常都会中断执行 - 即使它已被处理并且永远不会到达您的代码。您只需按“继续”即可继续执行或禁用第一次机会异常时的中断。这是另一个包含更多详细信息的线程: Invalid object name 'dbo.__MigrationHistory' using Database.Create; EF6.02 when connection string is passed in

关于c# - 仅在 Azure 计算模拟器中出现 EdmMetadata 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14718736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com