ASP.NET MVC-从SQL Server Express切换到精简版-连接问题 [英] ASP.NET MVC - Switching from SQL Server Express to Compact Edition - Connection Issue

查看:64
本文介绍了ASP.NET MVC-从SQL Server Express切换到精简版-连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC 4项目-带有实体框架的CodeFirst -已连接到EF生成的SQL Server Express数据库,并且运行良好.

I have a ASP.NET MVC 4 project - CodeFirst with Entity Framework - that was connected to a SQL Server Express database generated by EF and it was working just fine.

但是,我试图部署到AppHarbor,并且在运行与我的应用程序连接的SQL版本时遇到一些问题.

However, I am trying to deploy to AppHarbor and having some issues with the version of SQL running there connecting with my app.

因此,我注意到他们有一个利用SQL Server Compact Edition 4的示例项目.这是该项目的web.config文件:

So, I noticed that they have an example project that is utilizing SQL Server Compact Edition 4. Here is the web.config file for that project: https://github.com/friism/CodeFirstMigrations/blob/master/Web/Web.config

此外,我在Microsoft的ASP.NET站点上的项目中找到了有关如何包含SQL Server CE数据库的教程:

Also, I found a tutorial about how to include a SQL Server CE database in your project on Microsoft's ASP.NET site: http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-4

我决定在我的 App_Data 文件夹中创建一个 FranchiseManagerData.sdf 文件,并修改我的连接字符串和应用程序设置以匹配它们.这是我的Web.config的样子:

I decided to create a FranchiseManagerData.sdf file in my App_Data folder and modify my connection string and app settings to match theirs. Here's what my Web.config looks like:

<appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>

  <connectionStrings>
    <add name="FranchiseManagerEntities"
         connectionString="Data Source=|DataDirectory|FranchiseManagerData.sdf"
         providerName="System.Data.SqlServerCe.4.0"/>
  </connectionStrings>

运行应用程序时,出现DataException错误,提示:底层提供程序在打开时失败.

When I run my application, I get a DataException error that says: The underlying provider failed on Open.

似乎正在发生的事情是该应用程序仍在寻找由Entity Framework生成的旧数据库,该数据库的名称为: FranchiseManagerTest.Models.FranchiseManagerContext -EF在我之后将其命名数据上下文类.

It looks like what is happening is that the application is still looking for the old database that was generated by Entity Framework that had the name: FranchiseManagerTest.Models.FranchiseManagerContext - EF was naming it after my data context class.

这是停止调试后显示的错误:

Here is the error that is displayed after stopping debugging:

 Cannot open database "FranchiseManagerTest.Models.FranchiseManagerContext" requested by the login. The login failed.
Login failed for user 'COMPANY\UserName'.

我尝试清洁并重建解决方案.另外,我删除了bin文件夹的内容并再次进行了干净的重建,但是,它似乎仍在寻找旧的数据库连接.

I have tried cleaning and rebuilding the solution. Also, I've deleted the contents of the bin folder and did a clean rebuild again, however, it still seems to be looking for the old database connection.

我做错了什么?如何使我的项目查找我创建的本地SQL Server CE数据库而不是先前的数据库?

What am I doing wrong? How can I get my project to look for the local SQL Server CE database I made and not the previous database?

如果我需要提供更多详细信息,请告诉我.

If I need to supply any further details please let me know.

谢谢.

这是Web.config文件的System.Web部分的一部分:

Here is a portion of the System.Web section of my Web.config file:

<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"></customErrors>
<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>

推荐答案

FormsAuthentication在默认情况下不具有使用Sql CE的能力(据我所知).
我已经使用
EJ的SQL Server Compact 4.0 ASP.NET成员资格提供者没有任何问题.

FormsAuthentication doesn't by default have the ability to use Sql CE (to my knowledge).
I have used EJ's SQL Server Compact 4.0 ASP.NET Membership provider without any issues.

另外,听起来您必须更新Entity Framework连接才能正确使用SQL Server CE数据库.

Also, it sounds like you'll have to update your Entity Framework connection to use the SQL Server CE database correctly.

更新

从.Net 4.5开始,新的SimpleMemembership Provider和Univerasl Provider天真地支持Sql CE.

As of .Net 4.5, the new SimpleMemembership Providers and Univerasl Providers naively support Sql CE.

这篇关于ASP.NET MVC-从SQL Server Express切换到精简版-连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆