2012-12-13 66 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;" />