c# - 无法找到请求的 .Net Framework 数据提供程序。 (SQL客户端)

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

我正在尝试使用来自 SQL Server (2005) 的数据库优先迁移来设置一个简单的 ASP.NET MVC 4 webapp。我已经在数据库中创建了表,并使用 Entity Framework 在代码中创建了对象。我可以使用这些对象访问数据。

当我尝试在 Global.asax 中使用 WebSecurity.InitializeDatabaseConnection("FLMREntities", "UserProfile", "UserId", "UserName", true); 初始化 WebSecurity 时出现问题。 .cs 文件。我尝试使用模板附带的 InitializeSimpleMembershipAttribute 过滤器,但遇到了同样的问题。我收到错误消息:

Unable to find the requested .Net Framework Data Provider. It may not be installed.

这里是相关的连接字符串:

<add name="FLMREntities"
     connectionString="metadata=res://*/Models.FLMR.csdl|res://*/Models.FLMR.ssdl|res://*/Models.FLMR.msl;
                    provider=System.Data.SqlClient;
                    provider connection string=&quot;data source=notes.marietta.edu;
                        initial catalog=muskwater;
                        user id=muskwater;password=********;
                        MultipleActiveResultSets=True;
                        App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

另外,我在数据库中创建了成员表以匹配模板创建的内容。如果我将 Initialize 调用中的最后一个参数更改为 false(这样它就不会尝试自动创建表),它会返回找不到 UserProfile 表。我还尝试了名称的变体,例如 [dbo].[UserProfile]。

我所需要的只是有一个简单的帐户模型来允许用户登录并允许某些用户查看更多内容。

最佳答案

我遇到了类似的问题,我做了什么: 我修改了默认连接。我已经有了 edmx 模型的连接字符串,如下所示:

<add name="ChemicalReporterEntities" connectionString="metadata=res://*/ChemicalDB.csdl|res://*/ChemicalDB.ssdl|res://*/ChemicalDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLExpress;initial catalog=ChemicalReporter;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

但我不能将它与 SimpleMemebrship 提供程序一起使用。所以在 Visual Studio 中,我打开了服务器资源管理器 > 数据连接,我选择了我的连接,右键单击属性,然后从那里复制了连接字符串并将其粘贴到 defaultConnection:

<add name="DefaultConnection" connectionString="Data Source=.\SQLExpress;Initial Catalog=ChemicalReporter;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework" providerName="System.Data.SqlClient" />

之后,我将 WebSecurity.InitializeDatabaseConnection 更改为使用 DefaultConnection。

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", true);

关于c# - 无法找到请求的 .Net Framework 数据提供程序。 (SQL客户端),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15205400/

相关文章:

c# - 使用 count() 优化 linq 查询

c# - 使用 View ,抽象实际表,使用 View 更新多个表

sql-server - 无法在 SQL Server 2019 数据库中创建数据库关系图

asp.net-mvc - asp.net MVC OutputCache 属性的默认持续时间是多少?

c# - 使用带有 CaSTLe 代理拦截器的简单注入(inject)器

c# - 正则表达式匹配由任何字符分组包围的可选组

sql - 使用 case 语句有条件地设置变量

sql-server - 停止 SQL Server 在 WHERE 子句中评估无用的 UPPER/LOWER?

html - 如何将网页内容堆叠成两列并保持页面大小一致

asp.net-mvc - C# 中的 SelectList 下拉菜单(选定值)