This project is read-only.

Membership provider - stuck on part 7

Jul 6, 2011 at 8:10 PM

I can't log in to StoreManager. And I can't create user or role. I have SQL connection error. Also on Security tab I see 2 users and 0 roles. I checked in tables - there's 1 role and 2 users.

I have VS 2010 SP1 and SQL 2008 installed on the named instance SQL2008DEV - I've attached ASPNETDB.MDF from completed solution to SQL (with the name "aspnetdb")

so my connection strings are


<add name="MusicStoreEntities"     connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf"     providerName="System.Data.SqlServerCe.4.0"/>   

<add name="MembershipSQLProvider"     connectionString="Data Source=.\SQL2008DEV;Initial Catalog=aspnetdb;Persist Security Info=True;User ID=asp;Pwd=111"     providerName="System.Data.SqlClient" /> 


Connection string are OK - I can open in server explorer and browse without problems. Without membership Store Manager works OK.

I put a breakpoint in ActionController : authentification went OK ( Membership.ValidateUser(model.UserName, model.Password) == true ) but after Redirect(returnUrl) I'm getting an error :

SQLExpress database file auto-creation error: The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory

I searched my solution (I followed all steps of the tutorial) - there's no connection string with SQLExpress or App_Data anywhere.




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



Jul 9, 2011 at 8:50 PM
Edited Jul 9, 2011 at 8:50 PM

I think the problem is that you've only pointed membership to your new database, but roles (mapping users to roles, necessary for assigning a user to the Administrator role) hasn't been set and is still pointing at the default, which is SQL Express. You also need to configure your role provider in your web.config. See the following description:

So the role / membership portion of your web.config would look like this:


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


Jul 11, 2011 at 3:33 PM

Thanks. It's solved the problem.

Aug 21, 2011 at 9:20 PM

Hello, i have a question: could we use a SQL Server CE instead of commercial versions of SQL Server? If so, how could we connect to it: the standart connection string doesn't work

<add name="MembershipSQLProvider" connectionString="Data Source=|DataDirectory|aspnetdb.sdf"  providerName="System.Data.SqlServerCe.4.0"/>

Aug 29, 2011 at 2:05 PM

Experiencing the same problem as eugeneL. (lol on the same name) I'm following the version3 of the tutorial and I can't seem to get the tool working.

    <add name="MusicStoreEntities"
         connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf"

Aug 29, 2011 at 2:16 PM

Whoopss. got it working. This is weird but for some strange reason my SQL Server Express service wasn't started thus the error. Make sure you check your services to see if SQL Server is started. :D

Aug 29, 2011 at 7:52 PM

In my case, it was a different subversion of SQL Server CE. I had to redownload and reinstall the SQL Server CE. It's not very obvious, because SQL Server 2008 Developer's edition include CE 4.0 version already

Sep 2, 2011 at 10:13 PM

Both Eugenes:

Glad you got this figured out. I think installing via WebPI should check for your SQL Server CE version, but I'm not sure. So are you using the Universal Providers for membership?