如何将代码优先实体框架 4 构建的数据库与远程服务器上的成员资格同步

发布于 2024-12-06 11:53:28 字数 4727 浏览 4 评论 0原文

我已经开始使用 SQL Express 2008 R2 构建 ASP net MVC 2.0 Web 应用程序。我在 somee.com 上托管该应用程序。

我决定使用 Entity Framework 4 和数据库的代码优先实现,以便能够轻松更改设计。它在本地运行良好,但是当我将其部署到我的主机提供商上时,出现了很多问题。

首先,如果模型发生变化,我无法重新初始化数据库,因为数据库大多数是预先在托管网站上创建的。因此,我没有这样做的权限。

好吧,我决定在本地服务器 SQLEXPRESS 上获取 .mdf 文件并将其发送到主机服务器上,但由于某种原因,当我向会员注册新用户时,我无法连接到数据库。这是发生异常的地方:

    _provider.CreateUser(userName, password, email, null, null, true, null, out status);

错误:

无法打开登录请求的数据库“People”。登录失败。用户“dalya”登录失败。

现在,我有一种感觉,通过获取本地 SQL EXPRESS 服务器的 DATA 文件夹中的 mdf 文件,其权限可能与我的大多数提供商在附加该文件时给出的权限不同。不过,这是我的 Web.config 文件:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->

<configuration>

  <connectionStrings>
    <!--
    <add name="People" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=People;" 
         providerName="System.Data.SqlClient" />
-->


    <add name="People"
       connectionString="Data source=PraxtPeople.mssql.somee.com;
                              packet size=4096;
                              user id=dalya;
                              pwd=********;
                              persist security info=False;
                              initial catalog=People;
                              "
       providerName="System.Data.SqlClient"/>


    </connectionStrings>

  <appSettings>
    <add key="DefaultConnectionString" value="People"/>
    <add key="webpages:Version" value="1.0.0.0"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>

    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>

    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="People"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="People" applicationName="/" />
      </providers>
    </profile>

    <roleManager enabled="false">
      <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="People" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>

    <pages>
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

任何人都可以告诉我如何解决这个问题吗?或者有谁知道一个好的主机提供商,它允许代码优先的实体框架 4.0 实现,如果设计发生变化,可以在运行时重新创建使用成员资格的数据库,而无需麻烦?

谢谢您的帮助,

I've started building a ASP net MVC 2.0 web application using SQL Express 2008 R2. I'm hosting the application on somee.com.

I decided to use Entity Framework 4 with a code-first implementation of the database as to be able to easily change the design. It works fine locally, but when I deploy it on my host provider a lot of problems appear.

First of all, I can't manage to reinitialise the database if the model has changed, since the database most be created beforehand on the hosting website. Hence, I don't have the permissions to do so.

So OK, I decide to fetch the .mdf file on my local server SQLEXPRESS and to send it on the host server, but then for some reason I can't connect to the database when I register a new user with Membership. The is where the exception occurs:

    _provider.CreateUser(userName, password, email, null, null, true, null, out status);

The error:

Cannot open database "People" requested by the login. The login failed. Login failed for user 'dalya'.

Now, I have a feeling that by fetching the mdf file in the DATA folder of my local SQL EXPRESS server, the permissions might be different then the permissions given by my most provider when it attached the file. Still, here is my Web.config file:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->

<configuration>

  <connectionStrings>
    <!--
    <add name="People" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=People;" 
         providerName="System.Data.SqlClient" />
-->


    <add name="People"
       connectionString="Data source=PraxtPeople.mssql.somee.com;
                              packet size=4096;
                              user id=dalya;
                              pwd=********;
                              persist security info=False;
                              initial catalog=People;
                              "
       providerName="System.Data.SqlClient"/>


    </connectionStrings>

  <appSettings>
    <add key="DefaultConnectionString" value="People"/>
    <add key="webpages:Version" value="1.0.0.0"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>

    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>

    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="People"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="People" applicationName="/" />
      </providers>
    </profile>

    <roleManager enabled="false">
      <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="People" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>

    <pages>
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Could anyone give me an idea on how to resolve this? Or does anyone know a good host provider that permits code-first entity framework 4.0 implementation, where databases using Membership can be recreated in runtime without hassle if the design changes?

Thank you for any help,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

送君千里 2024-12-13 11:53:28

尝试将 persist security info=False; 更改为 persist security info=True;

Try to change persist security info=False; to persist security info=True;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文