web.config and membership database - from development to production

5.5k views Asked by At

I'm trying to host my first ASP.NET project, after the initial upload via FTP I got SQL connection Errors, so after doing some searching I figured it was my Connection String, so I fixed it by properly putting my hosts info:

 <add name="orangefreshConnectionString1" connectionString="Data Source=<server>;Initial Catalog=<catalog>;User Id=<user>;Password=<pwd>;" providerName="System.Data.SqlClient" />

So this fixed my problem, my Website is up now... except for when I try to login, I get another SQL connection error.

I use 2 databases on my website: dbstart and ASPNETDB (last one for membership)

ASPNETDB is handled on my development web.config as: providers>

      <clear />
      <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
  </providers>

I know there is something that needs to be changed here, but my google queries have not been helpful so far in finding an answer...

Here is my development web.config content:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <connectionStrings>
    <add name="orangefreshConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\orangefresh.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
    <add name="orangefreshEntities" connectionString="metadata=res://*/App_Code.Orangefresh.csdl|res://*/App_Code.Orangefresh.ssdl|res://*/App_Code.Orangefresh.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\orangefresh.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <system.web>
    <customErrors mode="Off"/>
      <membership>
          <providers>
              <clear />
              <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
          </providers>
      </membership>
    <roleManager enabled="true" />
      <authentication mode="Forms">
          <forms loginUrl="default.aspx"></forms>
      </authentication>
    <pages theme="orangefresh" />
    <compilation debug="false" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>
      <buildProviders>
        <add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider" />
      </buildProviders>
    </compilation>
    <httpRuntime requestValidationMode="2.0" />
  </system.web>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="João &lt;[email protected]&gt;">
        <network host="host" userName="user" password="pass" />
      </smtp>
    </mailSettings>
  </system.net>
    <location path="Management">
        <system.web>
            <authorization>
                <allow roles="Admin"/>
                <deny users="*"/>
            </authorization>
        </system.web>
    </location>
</configuration>

How can I properly refer to my membership database on web.config?

2

There are 2 answers

1
TheGeekYouNeed On BEST ANSWER

Change inside of this:

<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>

the

connectionStringName="LocalSqlServer"

to

connectionStringName="orangefreshConnectionString1" 

or

connectionStringName="orangefreshEntities"

I can't tell which connection you use for what, but that is what needs changed.

0
paparazzo On

Yes you backup the original SQL database then restore over the top. But you can't just start with restore. You need to prep with the tool. On the SQL restore you need to check a replace option. Also in security on the database you may need to drop and re add the users and the user may have the same name but likely not the same internal id.