2

So I have created a database and built some things on top. Can I alter the Account modelview and controller so all Identity information adds to my database instead of the default?

4
  • Which database is used is simply a matter of setting the connection string. Commented Feb 26, 2014 at 23:06
  • Thanks, So seeing as I haven't used it yet, If I remove the default string - <add name="DefaultConnection" connectionString="Data and only have <add name="WOMSEntities" connectionString=", surely I need to stipulate which database to use in the controllers etc? Commented Feb 26, 2014 at 23:29
  • You can just keep the name as "DefaultConnection" and just change the connectionString attribute to your new connection string. If you change the name to "WOMSEntities", you'll have to change the DbContext constructor to use the new connection string name. Commented Feb 27, 2014 at 0:04
  • Oh wow that's cool. Then it will script and add relevant tables to my DB? As I said I built this database first and was under the impression that identity was difficult/impossible to implement this way. Commented Feb 27, 2014 at 0:14

1 Answer 1

2

Out of the box, you have an ApplicationDbContext defined as such:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {
    }
}

To change the connection string, either:

  1. Change the properties of the existing DefaultConnection connection string in your web.config
  2. Add a new connection string in your web.config, and change the ApplicationDbContext constructor to pass in the new name.
Sign up to request clarification or add additional context in comments.

9 Comments

Hi Brendan. Thanks for this. How are the database tables generated etc? When Identity features are first used? Will I have to add these myself? Thanks
The tables are created in the database via code-fist migrations. You shouldn't need to create them yourself.
Thanks. So if I configure it as you stated and register an duff account it will all be generated?
how come I now have: private WOMSEntities db = new WOMSEntities(); Error 2 The type or namespace name 'WOMSEntities' could not be found (are you missing a using directive or an assembly reference?)
Has the db altered the WOMSEntities db somehow?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.