locked
Relocating Identity Database RRS feed

  • Question

  • User-1368902223 posted

    Like many people, I suppose, most of my database driven web sites run off of 2 servers, one for IIS and all of the web stuff and one for SQL Server and other database-related stuff.

    In the past, when I create a new site in VS from a template and I want to take advantage of membership or identity, VS seems to want to look for or install the identity database on the web server.  I do not want this (for a variety of reasons that are irrelevant to this question).

    Also in the past, I have tried, to move or recreate this database (on to my database server where I want it) and then 'point' the connection string to the new location.

    All of the efforts seem to end in disaster with a total mess.  There seem to be all sort of versions of the identity/membership database and the attendant utilities to create them.  Connection strings seem to differ wildly as well as the specifics of changing where they point.

    So I am about to embark a couple of new ASP.NET projects and, as I detailed above, I have a web server going and a database server going (Windows Server 2012, SQL Server 2014, etc.).  I want the identity database on my already-existing SQL Server instance (which is NOT on the same server where IIS is installed and the web site itself will be installed.

    When I go to create the new project in VS, what is my best bet for accomplishing my goal of 1) using a template, 2) using Identity and 3) having the identity database on my database server within my existing SQL Server instance.

    Thanks in advance.

    Tuesday, August 23, 2016 5:54 PM

Answers

  • User283571144 posted

    Hi stevenfrankeventium,

    When I go to create the new project in VS, what is my best bet for accomplishing my goal of 1) using a template, 2) using Identity and 3) having the identity database on my database server within my existing SQL Server instance.

    As far as I know, ASP.Net Identity uses Entity Framework Code First.

    Therefore, before running your application first time, you want to update Connection String same as existing database which is normally inside ApplicationDbContext.

    Like below(IdentityModels.cs):

      public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
        {
            public ApplicationDbContext()
                : base("DefaultConnection", throwIfV1Schema: false)
            {
            }
    
            public static ApplicationDbContext Create()
            {
                return new ApplicationDbContext();
            }
        }

    Then you just need to change the connectionStrings in web config.

    For example:

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

    Identity will create its tables inside that existing database.

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 24, 2016 9:16 AM