IT Nota

  • Home
  • How To
  • .NET
  • WordPress
  • Contact

How to Setup User Access and Roles in Production SQL Server

Setting up ASP.NET membership and roles in development is very easy to do since out of the box, it’s already configured to use the built-in SQL Server Express provider. To set it up, you just need to launch ASP.NET Web Site Administration Tool by clicking on ASP.NET Configuration icon in the Solution Explorer or choose the ASP.NET Configuration option from the Project menu.

ASP.NET Configuration icon

Once you complete the configuration, a SQL Server Express database named Aspnetdb.mdf is created locally and ready to use. While this is very practical and suitable for development, it’s definitely not the best practice for production. It is highly recommended that a full-blown SQL Server is used in the production environment instead.

For a more detailed instructions on how to setup the user and roles in localhost, refer to the step-by-step guide from Scott Guthrie, Walkthrough: Managing Web Site Users with Roles included in the Further Reading on the bottom of this post.

Setting Up Application Services in Production

Configuring ASP.NET 4.0 Application Services to Use SQL Server 2008 in production database can also be done quite painlessly. The first step is to find ASP.NET SQL Server Setup Wizard on your local ASP.NET installation. Open a command-line window by opening the Start Menu and typing ‘cmd’ (without quotes) in the search box.

Change to directory C:\Windows\Microsoft.NET\Framework\v4.0.30319
or C:\Windows\Microsoft.NET\Framework\v2.0.50727 if you’re still using .NET Framework 2.0 or 3.5.

Look for a file called aspnet_regsql.exe and run it. By default when run without any parameters, it actually uses -W (Wizard mode) argument. You can use -? argument to see the list of all available parameters.

aspnet_regsql.exe from Command Line Window

ASP.NET SQL Server Setup Wizard Welcome Screen

ASP.NET SQL Server Setup Wizard Setup Option

ASP.NET SQL Server Setup Wizard Select the Server and Database

Substitute SQLSERVERPROD with your SQL Server Production server name and YOUR_DB_NAME with the database name where you want your application services configured. Then click Next >.

ASP.NET SQL Server Setup Wizard Confirm Your Settings

Click Next > and the wizard will run for a while until you see this screen:

ASP.NET SQL Server Setup Wizard The database has been created or modified.

Click Finish and a new and empty Membership and Roles infrastructure is ready to use in your production database.

Setup Web.Config Parameters

The second step is to update the ConnectionStrings in your Web.config file. If you use Visual Studio 2010 and .NET Framework 4.0, it’s even better as you only need to add the settings for your PROD in Web.Release.config file and never need to worry about switching the parameters between the DEV and PROD afterwards.

Web.config

<connectionStrings>
  <add name="AspNetSqlRoleProvider" 
    connectionString="Server=.SQLEXPRESS;
    Database=YOUR_DB_NAME_DEV;
    Trusted_Connection=yes" 
    providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
  <roleManager enabled="true" 
    defaultProvider="LocalSqlServer">
    <providers>
      <clear />
      <add name="AspNetSqlRoleProvider"
        applicationName="/" 
        connectionStringName="LocalSqlServer" 
        type="System.Web.Security.SqlRoleProvider" />
    </providers>
  </roleManager>
</system.web>

Web.Release.config

<connectionStrings>
  <add name="AspNetSqlRoleProvider" 
    connectionString="Data Source=SQLSERVERPROD;
    Persist Security Info=True;
    Initial Catalog=YOUR_DB_NAME;
    User ID=myuserid;Password=dbpassword123"
    providerName="System.Data.SqlClient"
    xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</connectionStrings>

The new database is going to be empty and this is what I like best as I don’t want to copy over various test user ids to production.

Further Reading:
Walkthrough: Managing Web Site Users with Roles
Configuring ASP.NET 2.0 Application Services to Use SQL Server 2000 or SQL Server 2005
Users and Roles On The Production Website (C#)

January 18, 2012 Filed Under: .NET, How To Tagged With: ASP.NET, MVC

Buy me a coffee?

Buy me a coffee If you find any of the articles or demos helpful, please consider supporting my work here, you'll have my big thanks!

Buy me a coffee Support this site
Buy Me a Coffee?

Categories

  • .NET
  • Coding
  • Cybersecurity
  • Database
  • How To
  • Internet
  • Multimedia
  • Photography
  • Programming
  • Resources
  • Review
  • Tips and Tricks
  • Uncategorized
  • Use Case
  • WordPress
  • Writing

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Tags

.NET .NET Core AdSense ASP.NET Cdonts Dll Classic ASP Code Editor ETL FSharp Genesis Framework Git Google HP Asset Manager HTML5 Hugo IIS Information Security Internet Internet Information Services iOS JAMStack Linux macOS Microsoft Microsoft SQL Server MVC PHP PowerShell Python Simple Mail Transfer Protocol Smtp Server SQL SQL Server SSIS SSMS SSRS Sublime Text Visual Studio Visual Studio Code VPN Windows Windows 8 Windows 10 Windows 2012 Windows Server

Copyright © 2011-2025 IT Nota. All rights reserved. Terms of Use | Privacy Policy | Disclosure