Creating ASP.NET WebApplication/ASP.NET MVC Application Membership Database on SQL Server rather than LocalDb
I was asked this question from one of my blog reader: How can a DB be created in SQL Server rather than locally (LocalDb) which is default?
When you create new ASP.NET MVC Application (using regular template ‘Internet’) or ASP.NET WebApplication, you will notice the following connectionString in Web.config file:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication1-20121005163323;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication1-20121005163323.mdf" providerName="System.Data.SqlClient" />
Actually this helps MVC Application or ASP.NET WebApplication to generate database locally (within project in App_Data folder) at run-time for accounts/login management (membership). If however you want to generate this database in SQL Server then you can make some quick changes in the above Web.config file to do that, so here is what you need to replace in the above db mapping.
<add name="DefaultConnection" connectionString="Data Source=ITORIAN-PC;Initial Catalog=ASPNETMembership;Integrated Security=True;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
You probably have a different data sources so change it before running. Now, run the application and click on ‘Register’ link to create an account and then you are all done.
Open the SQL Server Management Studio and look at the generated DB for this application.