ASP.NET Configuration Website For Membership - database setup (aspnet_ tables) - having problems pointing to the right database

StackOverflow https://stackoverflow.com/questions/15822088

Question

I'm setting up membership in my ASP.NET MVC4 app, so I open the solution and then from there, I open up the ASP.NET Configuration website option under the "Project" menu. This opens up the ASP.NET Configuration tool to create/modify/delete users. What I'm finding is when I create a user, it creates the user in a local database when I specifically set in the web.config to point to a DIFFERENT database hosted with my web hosting company. I put <remove name="LocalSqlServer" /> to remove the connection defined in machine.config.

Here's the connection string in the web.config for my app:

<remove name="LocalSqlServer" />
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=cp.speedwell.arvixe.com; Initial Catalog=*********; User ID=********; Password=********;" />

Here's my database structure that's with my web hosting company. As you can see, I have all of the aspnet_ tables already created:

enter image description here

When I click on "Providers" in the ASP.NET Configuration tab, here's my list of providers:

enter image description here

DefaultMembershipProvider is pointed to "DefaultConnection" which is the connection string to the database hosted with my web hosting company. When I click "Test", it immediately comes back saying:

enter image description here

Finally, when I click on Security, here's the message I get (keep in mind I removed LocalSqlServer from my connection strings):

enter image description here

Any ideas what I'm doing wrong?

UPDATE

Here are my Membership, Profile, RoleManager, and SessionState sections of my web.config:

<profile defaultProvider="DefaultProfileProvider">
  <providers>
    <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
  </providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
  <providers>
    <add connectionStringName="DefaultConnection" enablePasswordRetrieval="false"
      enablePasswordReset="true" requiresQuestionAndAnswer="false"
      requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6"
      minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
      applicationName="/" name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </providers>
</membership>
<roleManager enabled="true" defaultProvider="DefaultRoleProvider">
  <providers>
    <add connectionStringName="DefaultConnection" applicationName="/"
      name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
  <providers>
    <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
  </providers>
</sessionState>
Was it helpful?

Solution 4

Turns out, my Users/Roles/Etc were actually being inserted into the correct database all along- they were being inserted into the Users table, not the aspnet_Users table, as I would expect. This is because my app was configured to use the asp.net universal providers.

Since I'm using MYWSAT, and it requires the old aspnet tables, I removed the universal providers and it now has moved past that problem. The reason I was getting that message saying that it couldn't establish a connection to the database was exactly because of this.

OTHER TIPS

In your Web.config, Just replace this,

<membership defaultProvider="DefaultMembershipProvider">
  <providers>
    <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
  </providers>
</membership>

with this,

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

You do not need to remove LocalSqlServer instead you need to remove DefaultConnection.

<remove name="DefaultConnection" />
<add name="DefaultConnection" providerName="System.Data.SqlClient" .../>

Beside, if you use new ASP.Net Universal Providers, you do not need to use aspnet_regsql.exe to generate tables which is deprecated.

ASP.Net Universal Providers uses Entity Framework.

If your database is new (no existing data), my suggestion will be to delete that database and use ASP.Net Universal Providers to create tables (no need to use aspnet_regsql.exe).

Place <clear/> inside tag before add.

<profile defaultProvider="DefaultProfileProvider">
  <providers>
    <clear/>
    <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
  </providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
  <providers>
    <clear/>
    <add connectionStringName="DefaultConnection" enablePasswordRetrieval="false"
      enablePasswordReset="true" requiresQuestionAndAnswer="false"
      requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6"
      minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
      applicationName="/" name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </providers>
</membership>
<roleManager enabled="true" defaultProvider="DefaultRoleProvider">
  <providers>
    <clear/>
    <add connectionStringName="DefaultConnection" applicationName="/"
      name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
  <providers>
    <clear/>
    <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
  </providers>
</sessionState>

Is your web.config pointing to that connection string for membership via connectionStringName like so:

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

Or could you be having build configuration issues? Have you verified that the uploaded config file is pointing to the right place?

Also try adding a clear before your declaration of membership:

<membership defaultProvider="DefaultMembershipProvider">
<providers>
 <clear />    
<add name="DefaultMembershipProvider" ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top