0

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

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

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

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

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

错误:

无法打开登录请求的数据库“人员”。登录失败。用户 '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 实现的良好主机提供程序,如果设计更改,可以在运行时重新创建使用 Membership 的数据库而无需麻烦?

感谢您的任何帮助,

4

1 回答 1

1

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

于 2012-01-31T11:15:32.690 回答