Richard77
Richard77

Reputation: 21621

How to keep membership and my data in the same database?

I'd like to store all my membership and my data in the same database. I've started by creating a database called MembershipDB where I added membership schema using aspnet_regsql.exe.

I'm using Internet ASP.NET MVC4 template. So this is the connection string

 <connectionStrings>
  <remove name="DefaultConnection"/>
  <add name="DefaultConnection" 
     connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=MembershipDB.mdf;
     Integrated Security=True;" 
      providerName="System.Data.SqlClient" />
 </connectionStrings>

When I create a user, I don't see any data in the MembershipDB database I created previously. Instead, I see another database called MembershipDB.mdf that was created and that contains the data.

Why my database is not getting the data, instead another database with the same name is being created?? Code first is supposed to create a new database only if it doesn't find one with the same name.

Thanks for helping.

Upvotes: 0

Views: 99

Answers (3)

Display Name
Display Name

Reputation: 4732

I think the best approach (I use it all the time) is to look and watch what others do in these cases and repeat after them.

Here is an article (although EF 4.1, not 5) on how to use EF and membership together (and this is what you're after if I understood your question correctly:

Using Entity Framework Code First and ASP.NET Membership Together

Here is successfully answered question on SO (same topic) (wonder how didn't you found this one prior to asking yours):

Best database design approach to join complex data to ASP.Net Membership tables

Please let me know if this is of help.

Upvotes: 0

Judo
Judo

Reputation: 5247

  1. Just use the database name as in the connection string without the .mdf extention.

  2. Set connectionStringName="MembershipDB" in the Membership section of web.config

Upvotes: 1

Kenneth Fisher
Kenneth Fisher

Reputation: 3812

Your connection string specifies an initial catalog(database) of MembershipDBA.mdf. Change it to MembershipDB. The .mdf part is just a standard file extension for the data part of the database. There is no need to reference it unless you are specifically changing something to do with the files.

Upvotes: 1

Related Questions