如何使用EF应用程序为我的ASP.NET MVC设置SQL Server连接

时间:2016-03-02 20:32:39

标签: c# sql-server asp.net-mvc entity-framework

我非常擅长设置SQL Server数据库并连接到它(Visual Studio 2012 for Web)。我已经下载了SQL Server 2014,并且在我的服务中运行了SQL Server(Express)。

我对下一步应该是什么一无所知,我使用SQL Server Express在Database Explorer视图中设置数据连接,但是当我在Package Manager Console中尝试update-database时,我得到了

  

提供程序未返回ProviderManifest实例

这可能是因为我的连接字符串错误。

连接字符串:

<add name="DefaultConnection" 
     connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=RecreationalServices;Integrated Security=False" 
     providerName="System.Data.SqlClient" />

Check IMAGE CLICK HERE

全文错误代码

PM> update-database
  

没有待定的基于代码的迁移。
  System.Data.ProviderIncompatibleException:提供程序未返回ProviderManifest实例。 ---&GT; System.ArgumentException:无法确定存储版本;需要有效的存储连接或版本提示   在System.Data.SqlClient.SqlVersionUtils.GetSqlVersion(String versionHint)
  在System.Data.SqlClient.SqlProviderManifest..ctor(String manifestToken)
  在System.Data.SqlClient.SqlProviderServices.GetDbProviderManifest(String versionHint)
  在System.Data.Common.DbProviderServices.GetProviderManifest(String manifestToken)
  ---内部异常堆栈跟踪结束---
  在System.Data.Common.DbProviderServices.GetProviderManifest(String manifestToken)
  在System.Data.Metadata.Edm.StoreItemCollection.Loader.InitializeProviderManifest(Action 3 addError)
at System.Data.Metadata.Edm.StoreItemCollection.Loader.OnProviderManifestTokenNotification(String token, Action
3 addError)
  在System.Data.EntityModel.SchemaObjectModel.Schema.HandleProviderManifestTokenAttribute(XmlReader reader)
  在System.Data.EntityModel.SchemaObjectModel.Schema.HandleAttribute(XmlReader阅读器)
  在System.Data.EntityModel.SchemaObjectModel.SchemaElement.ParseAttribute(XmlReader reader)
  在System.Data.EntityModel.SchemaObjectModel.SchemaElement.Parse(XmlReader阅读器)
  在System.Data.EntityModel.SchemaObjectModel.Schema.HandleTopLevelSchemaElement(XmlReader阅读器)
  在System.Data.EntityModel.SchemaObjectModel.Schema.InternalParse(XmlReader sourceReader,String sourceLocation)
  在System.Data.EntityModel.SchemaObjectModel.Schema.Parse(XmlReader sourceReader,String sourceLocation)
  at System.Data.EntityModel.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable 1 xmlReaders, IEnumerable 1 sourceFilePaths,SchemaDataModelOption dataModel,AttributeValueNotification providerNotification,AttributeValueNotification providerManifestTokenNotification,ProviderManifestNeeded providerManifestNeeded,IList 1& schemaCollection)
at System.Data.Metadata.Edm.StoreItemCollection.Loader.LoadItems(IEnumerable
1 xmlReaders,IEnumerable 1 sourceFilePaths)
at System.Data.Metadata.Edm.StoreItemCollection.Init(IEnumerable
1 xmlReaders,IEnumerable 1 filePaths, Boolean throwOnError, DbProviderManifest& providerManifest, DbProviderFactory& providerFactory, String& providerManifestToken, Memoizer 2&amp; cachedCTypeFunction)
  在System.Data.Metadata.Edm.StoreItemCollection..ctor(IEnumerable 1 xmlReaders)
at System.Data.Entity.Migrations.Extensions.XDocumentExtensions.GetStoreItemCollection(XDocument model, DbProviderInfo& providerInfo)
at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(XDocument sourceModel, XDocument targetModel, String connectionString)
at System.Data.Entity.Migrations.DbMigrator.IsModelOutOfDate(XDocument model, DbMigration lastMigration)
at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable
1 pendingMigrations,String targetMigrationId,String lastMigrationId)
  在System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations,String targetMigrationId,String lastMigrationId)
  在System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
  在System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
  在System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()          在System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()       提供程序未返回ProviderManifest实例。

2 个答案:

答案 0 :(得分:0)

尝试将集成安全性从False更改为True。

答案 1 :(得分:0)