Use SQL Express with your MVC4 Single Page Application

Currently playing with Visual Studio 2012 and MVC4, I’ll quickly share how to properly set up your membership provider to use SQL Server Express.

1. Install Visual Studio 11 beta

2. Install SQL Server Express 2012

3. Start Visual Studio, create a new project, select MVC4, then Single Page Application,

4. In SQL Server Management Studio, create a new database

5. Run aspnet_regsql.exe (in C:WindowsMicrosoft.NETFramework64v4.0.30319) and follow the steps. This will create the required tables in your new database to manage the different .Net providers (membership, profiles, roles, etc..).

6. In your application web.config, add a new connection string that points to your SQL Express. Should look like the following with SQL authentication:

<add name=”SQLExpressConnection” connectionString=”Data Source=.SQLExpress;Initial Catalog=mydatabase;User Id=sa;Password=password” providerName=”System.Data.SqlClient” />

And Windows authentication:

<add name=”SQLExpressConnection” connectionString=”Data Source=.SQLExpress;Initial Catalog=mydatabase;Integrated Security=true” providerName=”System.Data.SqlClient” />

7. Still in the web.config file, adapt the the DefaultMembershipProvider or add a new one in theĀ <membership><providers> section. To actually have your application use your provider, make sure you set the defaultProdiver attribute of the mmbership node to the provider you want to use. Otherwise, the machine.config settings will be used. And make sure, in your provider, to set the connectionStringName to the connection string you defined above.


And you’re good to go!

Leave a Reply

Your email address will not be published. Required fields are marked *