0

I have an aspnetservicesdb database that is used for storing user profiles. I have deployed a new asp.net mvc application. The application uses a local sqlexpress database in the appdata directory for membership/profile purposes.

I do not want the application to use the sqlexpress database.

I've removed the connection string from the web.config and AuthConfig.RegisterAuth(); from global.asax

So far, this has worked. I'm able to use User.Identity.Name in the controller succesfully. However, when I tried to use User.IsInRole in the view, I got a sql server not found error, becuase the local sqlexpress db doesn't exist.

How do I tell the application to use my existing database and stop looking for the sqlexpress db?

edit - here are the connection strings

<!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=removed;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|removed" providerName="System.Data.SqlClient"/>-->
    <add name="ApplicationServices" connectionString="Data Source=removed;Initial Catalog=aspservicesdb;UID=removed;PWD=removed" providerName="System.Data.SqlClient" />

edit - here are other membership portions from web config

<authentication mode="Forms">
  <forms loginUrl="~/login.aspx" timeout="2880" />
</authentication>
<membership userIsOnlineTimeWindow="480">
  <providers>
    <clear />
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="12" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
  </providers>
</membership>
tintyethan
  • 1,772
  • 3
  • 20
  • 44
  • Which version of MVC? Which Membership provider? (You say SqlMembershipProvider, but are you sure?) SqlMembershipProvider configures it's database in web.config, so you set the connection string there. What does EntityFramework have to do with anything? SqlMembershipProvider doesn't use EntityFramework. – Erik Funkenbusch Mar 27 '14 at 20:16
  • Yes, I'm sure. I've added my connection strings to the original question, including the commented out default for localdb. – tintyethan Mar 27 '14 at 20:19
  • Can you share the definition of your Entities Context? – Michael Dunlap Mar 27 '14 at 20:22
  • @MichaelDunlap I don't specify anything about the membership db in any other place, including the entities context. should I? – tintyethan Mar 27 '14 at 20:23
  • @MichaelDunlap I have a context with my modelBuilders, db properties and some other configuration setting. Is that what you're refering to? My entities are defined in an edmx in a seperate project. – tintyethan Mar 27 '14 at 20:27
  • @tintyethan - You need to provide your membership sections from your web.config as well – Erik Funkenbusch Mar 27 '14 at 20:32
  • @zimdanen - That's for SimpleMembership, not SqlMembershipProvider. – Erik Funkenbusch Mar 27 '14 at 20:32
  • @zimdanen Yes, I do have a connection string that is used for everything else - for data not related to membership. Is that relevant here? – tintyethan Mar 27 '14 at 20:33

2 Answers2

0

You're not telling asp.net to use the membership provider. That should look like this:

<membership defaultProvider="AspNetSqlMembershipProvider" userIsOnlineTimeWindow="480">

And, since you're getting membership some other way, that tells me you're probably using SimpleMembership, which means you need to remove the SimpleMembership code from your application (including the user data context, and other attributes)

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
  • This is the first I've heard of SimpleMembership. I've just now looked around a bit regarding this, but is there a resource that you would recommend for a guide on removing it? Thanks for your help. – tintyethan Mar 27 '14 at 21:06
  • I wanted to mention that the application is successfully getting user names from the old membership database both locally and on the server. The error occurs only on the server and only when I'm trying to access user roles. – tintyethan Mar 27 '14 at 21:23
  • @tintyethan - Well, you ignored my request for which version of MVC, and you stated you knew for sure you were using SqlMembershipProvider... If you're using MVC4 then there are some new things you need to learn. – Erik Funkenbusch Mar 27 '14 at 22:02
  • I'm sorry - yes - I'm using MVC 4. Are you suggesting there is something specific I need to know, or just generally speaking? Thanks again for your help. – tintyethan Mar 28 '14 at 01:18
  • I took a look at properties to be sure and I see "runtime version" v4.0.30319 but "version" 5.1.0.0 – tintyethan Mar 28 '14 at 02:32
0

It turns out I hadn't added these sections to the web config...

<profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
    </profile>
    <roleManager enabled="true">
      <providers>
        <clear />
        <add connectionStringName="ApplicationServices" applicationName="/"
          name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
    </roleManager>

The issue appears to be resolved.

tintyethan
  • 1,772
  • 3
  • 20
  • 44