0

1. If I create new MVC project it has default connection string :

< add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial
Catalog=aspnet-OneVeryBad.Web-20130301153805;Integrated   
Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-OneVeryBad.Web-20130301153805.mdf" 
providerName="System.Data.SqlClient" />

2. I create my context inheriting from DbContext :

public class BadContext : DbContext
{
    public BadContext() : base("BadContext")
    {
    }

    /* DbSets */
}

3. Change connection string name to BadContext to work with EF:

< add name="BadContext" connectionString="Data Source=(LocalDb)\v11.0;Initial 
Catalog=aspnet-OneVeryBad.Web-20130301153805;Integrated 
Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-OneVeryBad.Web-
20130301153805.mdf" providerName="System.Data.SqlClient" />

Now I sucessfully can store data to LocalDb, but cannot register users :

CREATE DATABASE permission denied in database 'master'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: CREATE DATABASE permission denied in database 'master'.

unless I change connection string back to original :

< add name="DefaultConnection" ...

I see my context tables and membership tables in local db through VS server explorer. But cannot make membership work with EF connection string. How can I solve this ? Originally I want to store all tables in localdb so that its always with me in the project wherever I go.

mishap
  • 8,176
  • 14
  • 61
  • 92

1 Answers1

0

You need to change the connection string name in the InitializeSimpleMembershipAttribute.cs file under the Filters folder.

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", 
    "UserId", "UserName", autoCreateTables: true);

To:

WebSecurity.InitializeDatabaseConnection("BadContext", "UserProfile", 
    "UserId", "UserName", autoCreateTables: true);

Did it occur to you to maybe use the Find In Files function to search for "DefaultConnection"?

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
  • Thanks, I had to change this one as well : public class UsersContext : DbContext { public UsersContext() : base("BadContext") { } } – mishap Mar 01 '13 at 21:14