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

本文关键字:设置 SQL Server 连接 MVC NET EF 何使用 应用程序 ASP 我的 | 更新日期: 2023-09-27 18:37:02

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

我不知道我的下一步应该是什么,我已经使用 SQL Server Express 在数据库资源管理器视图中设置了一个数据连接,但是当我尝试在包管理器控制台中update-database时,我得到

提供程序

未返回提供程序清单实例

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

连接字符串:

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

检查图片点击这里

全文中的错误代码

PM> update-database

没有挂起的基于代码的迁移。
System.Data.Provider不兼容异常:提供程序未返回 ProviderManifest 实例。---> System.ArgumentException:无法确定存储版本;需要有效的存储连接或版本提示。
at System.Data.SqlClient.SqlVersionUtils.GetSqlVersion(String versionHint)
at System.Data.SqlClient.SqlProviderManifest..ctor(String manifestToken)
at System.Data.SqlClient.SqlProviderServices.GetDbProviderManifest(String versionHint)
at System.Data.Common.DbProviderServices.GetProviderManifest(String manifestToken)
---内部异常堆栈跟踪结束---
at System.Data.Common.DbProviderServices.GetProviderManifest(String manifestToken)
at System.Data.Metadata.Edm.StoreItemCollection.Loader.InitializeProviderManifest(Action 3 addError)
at System.Data.Metadata.Edm.StoreItemCollection.Loader.OnProviderManifestTokenNotification(String token, Action
3 addError)
at System.Data.EntityModel.SchemaObjectModel.Schema.HandleProviderManifestTokenAttribute(XmlReader reader)
at System.Data.EntityModel.SchemaObjectModel.Schema.HandleAttribute(XmlReader reader)
at System.Data.EntityModel.SchemaObjectModel.SchemaElement.ParseAttribute(XmlReader reader)
at System.Data.EntityModel.SchemaObjectModel.SchemaElement.Parse(XmlReader reader)
at System.Data.EntityModel.SchemaObjectModel.Schema.HandleTopLevelSchemaElement(XmlReader reader)
at System.Data.EntityModel.SchemaObjectModel.Schema.InternalParse(XmlReader sourceReader, String sourceLocation)
at 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 providerManifestNeed, 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& cachedCTypeFunction)
at 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)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable'1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore() at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run() 提供程序未返回提供程序清单实例。

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

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

尝试使用向导创建模型,如以下示例 http://www.c-sharpcorner.com/UploadFile/4b0136/getting-started-with-wizard-in-Asp-Net-mvc-5-part-1/