2012-12-13 67 views
0

我正在學習如何使用asp.net與sql數據庫一起使用azure,並且很難嘗試通過我收到的錯誤。我正在遵循的教程是 - 「http://www.windowsazure.com/en-us/develop/net/tutorials/web-site-with-sql-database/#aspnetwindowsazureinfo」窗口Azure移植錯誤

在包管理器控制檯我輸入了「enable-migrations -ContextTypeName ToDoListApp.Models.ToDoDb」,並且正常工作,如下面的輸出所示。

Checking if the context targets an existing database... 
Code First Migrations enabled for project ToDoListApp. 

然後我在「添加遷移初始」和我收到此錯誤類型..

「不能腳手架接下來的遷移,因爲目標數據庫與一個版本的Code First早於EF創建4.3並且不包含遷移歷史記錄表要開始對該數據庫使用遷移,請確保當前模型與目標數據庫兼容並執行遷移更新過程(在Visual Studio中,您可以使用Package Manager中的Update-Database命令控制檯執行遷移更新過程)。「

我還使用了命令「-Verbose」 - 並發現錯誤在目標數據庫中。

Using StartUp project 'ToDoListApp'. 
Using NuGet project 'ToDoListApp'. 
Target database is: 'ToDoListApp.Models.ToDoDb' (DataSource: .\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention). 
  • 注:*我已經建立了在Azure上一個網站,與SQL數據庫一起,並通過發佈其鏈接到該項目中。

我已經輸入錯誤到谷歌,有人說「添加遷移InitialMigration -IgnoreChanges」能解決這個問題,從

「http://www.woohoo.uk.com/Blog/updating - 實體框架4-1與代碼的第一次遷移「

和其他人說,只是更新數據庫的包管理器控制檯,這似乎沒有工作,我遵循微軟提供的教程,一路上我收到了這個問題。

任何幫助解決這種情況將不勝感激,即時通訊使用visual studio 2012,c#asp.net mv3框架4.5。

在我的web.config文件

,我也有輸入的代碼

<entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <contexts> 
     <context type="ToDoListApp.Models.ToDoDb, ToDoListApp"> 
     <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion"> 
     <parameters> 
      <parameter value="ToDoDb_DatabasePublish"/> 
     </parameters> 
     </databaseInitializer> 
     </context> 
    </contexts> 
    </entityFramework> 

我在輸入 「添加遷移InitialMigration -IgnoreChanges」

和輸出的誤差..

System.InvalidOperationException: Failed to set database initializer of type     'System.Data.Entity.MigrateDatabaseToLatestVersion' for DbContext type 'ToDoListApp.Models.ToDoDb, ToDoListApp' specified in the application configuration. See inner exception for details. ---> System.TypeLoadException: Could not load type 'System.Data.Entity.MigrateDatabaseToLatestVersion' from assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 
    at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) 
    at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) 
    at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) 
    at System.Type.GetType(String typeName, Boolean throwOnError) 
    at System.Data.Entity.Internal.ConfigFile.DatabaseInitializerElement.GetInitializerType() 
    at System.Data.Entity.Internal.AppConfig.InternalApplyInitializers(Boolean force) 
    --- End of inner exception stack trace --- 
    at System.Data.Entity.Internal.AppConfig.InternalApplyInitializers(Boolean force) 
    at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() 
    at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) 
    at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) 
    at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) 
    at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() 
    at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) 
    at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() 
    at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() 
    at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() 
    at System.Linq.Queryable.Count[TSource](IQueryable`1 source) 
    at System.Data.Entity.Migrations.History.HistoryRepository.Exists[TContext](HistoryContextBase`1 context) 
    at System.Data.Entity.Migrations.History.HistoryRepository.GetPendingMigrations(IEnumerable`1 localMigrations) 
    at System.Data.Entity.Migrations.DbMigrator.GetPendingMigrations() 
    at System.Data.Entity.Migrations.Infrastructure.MigratorBase.GetPendingMigrations() 
    at System.Data.Entity.Migrations.Design.ToolingFacade.GetPendingMigrationsRunner.RunCore() 
    at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run() 
Failed to set database initializer of type 'System.Data.Entity.MigrateDatabaseToLatestVersion' for DbContext type 'ToDoListApp.Models.ToDoDb, ToDoListApp' specified in the application configuration. See inner exception for details. 

回答

1

fixed -

只需要我登錄sql服務器對象ex plorer並刪除表下的EdmMetadata,然後在web.config中輸入我的連接字符串,這裏有一個例子,如果有人讀過這個,並且有同樣的問題..

<add name="DefaultConnection" connectionString="server=tcp:* insert server name*.database.windows.net,1433;Database=* insert database name *;User ID=*insert username *@* insert server name*;Password={*insert password here *};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" />