EF更新数据库报错:初始化数据库时发生异常。有关详细信息

来源:互联网 发布:淘宝上下架规则 编辑:程序博客网 时间:2024/05/29 18:39
捕捉到 System.Data.DataException
  HResult=-2146233087
  Message=初始化数据库时发生异常。有关详细信息,请参见 InnerException。
  Source=EntityFramework
  StackTrace:
       在 System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
       在 System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
       在 System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
       在 System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
       在 System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
       在 System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
       在 System.Data.Entity.Internal.InternalContext.Initialize()
       在 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
       在 System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
       在 System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
       在 System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
       在 System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
       在 System.Data.Entity.DbSet`1.Add(TEntity entity)
       在 General.DAL.Sales.SalesDal.AddRelated(SalesModel t) 位置 d:\Dongyi\General\General.DAL\Sales\SalesDal.cs:行号 70
  InnerException: System.Data.ProviderIncompatibleException
       HResult=-2146233087
       Message=从数据库中获取提供程序信息时出错。这可能是 Entity Framework 使用的连接字符串不正确导致的。有关详细信息,请查看内部异常并确保连接字符串正确。
       Source=EntityFramework
       StackTrace:
            在 System.Data.Entity.ModelConfiguration.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection)
            在 System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)
            在 System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
            在 System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
            在 System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
            在 System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
            在 System.Data.Entity.Internal.InternalContext.Initialize()
            在 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
            在 System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
            在 System.Data.Entity.Internal.Linq.InternalSet`1.AsNoTracking()
            在 System.Data.Entity.Infrastructure.DbQuery`1.AsNoTracking()
            在 System.Data.Entity.DbExtensions.AsNoTracking[T](IQueryable`1 source)
            在 System.Data.Entity.Internal.EdmMetadataRepository.QueryForModelHash(Func`2 createContext)
            在 System.Data.Entity.Internal.InternalContext.QueryForModelHash()
            在 System.Data.Entity.Internal.ModelCompatibilityChecker.CompatibleWithModel(InternalContext internalContext, ModelHashCalculator modelHashCalculator, Boolean throwIfNoMetadata)
            在 System.Data.Entity.Internal.InternalContext.CompatibleWithModel(Boolean throwIfNoMetadata)
            在 System.Data.Entity.Database.CompatibleWithModel(Boolean throwIfNoMetadata)
            在 System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context)
            在 System.Data.Entity.Internal.InternalContext.<>c__DisplayClass8.<PerformDatabaseInitialization>b__6()
            在 System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
       InnerException: System.Data.ProviderIncompatibleException
            HResult=-2146233087
            Message=提供程序未返回 ProviderManifestToken 字符串。
            Source=System.Data.Entity
            StackTrace:
                 在 System.Data.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
                 在 System.Data.Entity.ModelConfiguration.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection)
            InnerException: System.Data.SqlClient.SqlException
                 HResult=-2146232060
                 Message=服务器 'NEMO-PC' 上的 MSDTC 不可用。
                 Source=.Net SqlClient Data Provider
                 ErrorCode=-2146232060
                 Class=16
                 LineNumber=1
                 Number=8501
                 Procedure=""
                 Server=.
                 State=2
                 StackTrace:
                      在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
                      在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
                      在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
                      在 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
                      在 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
                      在 System.Data.SqlClient.SqlDataReader.get_MetaData()
                      在 System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
                      在 System.Data.SqlClient.TdsParser.GetDTCAddress(Int32 timeout, TdsParserStateObject stateObj)
                      在 System.Data.SqlClient.SqlInternalConnectionTds.GetDTCAddress()
                      在 System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)
                      在 System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx)
                      在 System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction transaction)
                      在 System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction)
                      在 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
                      在 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
                      在 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
                      在 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
                      在 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
                      在 System.Data.SqlClient.SqlConnection.Open()
                      在 System.Data.SqlClient.SqlProviderServices.UsingConnection(SqlConnection sqlConnection, Action`1 act)
                      在 System.Data.SqlClient.SqlProviderServices.UsingMasterConnection(SqlConnection sqlConnection, Action`1 act)
                      在 System.Data.SqlClient.SqlProviderServices.GetDbProviderManifestToken(DbConnection connection)
                      在 System.Data.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)

                 InnerException: 



解决方法:启动Distributed Transaction Coordinator服务 原因暂未深究

解决办法: 1. 在windows控制面版-->管理工具-->服务-->Distributed Transaction Coordinator-->属性-->启动
        2.在CMD下运行"net start msdtc"开启服务后正常。

如果在第1步Distributed Transaction Coordinator 无法启动,则是因为丢失了日志文件,重新创建日志文件,再启动就行了。重新创建 MSDTC 日志,并重新启动服务的步骤如下:
(1) 单击"开始",单击"运行",输入 cmd 后按"确定"。
(2) 输入:msdtc -resetlog (注意运行此命令时,不要执行挂起的事务)
(3) 最后输入:net start msdtc 回车,搞定!


原创粉丝点击