2017-03-05 105 views
0

我可以啓用遷移,但我無法更新數據庫或添加遷移。當我嘗試禁用遷移,然後重新啓用我得到 「術語'禁用遷移'無法識別」,我試圖刪除包並重新安裝作爲管理運行,更改App.config行。 我在我的工作電腦和我的家裏有同樣的問題,我在這裏看了很多帖子,並且這些建議還沒有解決我的問題。無論我做什麼,當談到改變,我總是得到這個錯誤(將遷移,更新數據庫等)實體框架遷移問題:DbMigrationsConfiguration`1'拋出異常

PM> add-migration TTT 
System.TypeInitializationException: The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section connectionString. (C:\Users\bern4rdo\Desktop\BasicEntityApp\tmp9260.tmp line 8) 
    at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal) 
    at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors) 
    at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors() 
    at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey) 
    --- End of inner exception stack trace --- 
    at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey) 
    at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName) 
    at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName) 
    at System.Configuration.ConfigurationManager.get_ConnectionStrings() 
    at System.Data.Entity.Internal.AppConfig..ctor() 
    at System.Data.Entity.Internal.AppConfig..cctor() 
    --- End of inner exception stack trace --- 
    at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForAssembly(Assembly assemblyHint, Type contextTypeHint) 
    at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForContext(Type contextType) 
    at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..cctor() 
    --- End of inner exception stack trace --- 
    at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..ctor() 
    at BasicEntityApp.Migrations.Configuration..ctor() in C:\Users\bern4rdo\Desktop\BasicEntityApp\Migrations\Configuration.cs:line 10 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Data.Entity.Migrations.Utilities.MigrationsConfigurationFinder.FindMigrationsConfiguration(Type contextType, String configurationTypeName, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration() 
    at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run() 
    at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 
    at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges) 
    at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges) 
    at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0() 
    at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) 
The type initializer for ***'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception.** 
PM>* 

我檢查它引用的文件中

C:\用戶\ bern4rdo \桌面\ BasicEntityApp \ Migrations \ Configuration.cs:line 10

哪一行是連接字符串。我已經在下面列出了應用程序配置文件,但是如果我能夠在接下來要做的事情上獲得一個好的方向,我將非常感激。我已經排除了之類的權限,香港專業教育學院嘗試了不同的服務器等

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    </configSections> 
    <connectionString> 
    <add name="SalesContext" connectionstring="DataSource=BERNARDO\SQLEXPRESS; Initial Catalogue=BasicEntityApp; trusted security=true; trustedserverCertificate=false;" providername="System.Data.sqlClient" /> 
    </connectionString> 
    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> 
    </startup> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework"> 
     <parameters> 
     <parameter value="System.Data.SqlServerCe.4.0" /> 
     </parameters> 
    </defaultConnectionFactory> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
     <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" /> 
    </providers> 
    </entityFramework> 
    <system.data> 

    <DbProviderFactories> 
     <remove invariant="System.Data.SqlServerCe.4.0" /> 
     <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" /> 
    </DbProviderFactories> 
    </system.data> 
</configuration> 

回答

0

你的配置部分錯誤命名<connectionString>時,它其實應該<connectionStrings>

<connectionStrings> 
    <add name="SalesContext" connectionstring="DataSource=BERNARDO\SQLEXPRESS; Initial Catalogue=BasicEntityApp; trusted security=true; trustedserverCertificate=false;" providername="System.Data.sqlClient" /> 
</connectionStrings> 
+0

都嘗試。最初將它作爲connectionStrings:/將再次嘗試>。< – berni3mack

相關問題