Search code examples
asp.netentity-framework-4code-firstmembershipremote-server

How to sync Code-first Entity Framework 4 built database with Membership on remote server


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,


Solution

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