Using aspnet_regsql via the command line to setup membership roles and profiles only

When you setup the asp.net membership, profile, etc using the aspnet_regsql wizard its pretty much an all or nothing affair - it adds all of the possible features in one go with no option to select which features are added.

When setting up the login systems you only need to add the following feature support: Membership, Role Manager and Profiles. The two remaining features (Personalization and SQL Web event provider) are not needed.

So to only install the features you require you should use the command line version of the tool.

Note: The version listed below (v2.0.50727) is valid for both .net 2.0 and .net 3.5. Without going into the technical details .net 3.5 is a layer on top of 2.0 and the same tool is used for both versions.

If you are working with a version that is newer than 3.5 then check that versions folder for an updated version of this tool as it may be updated in future versions.

Getting the command window open (Windows Vista)

  1. Click the start button then copy and paste this into the search box C:\Windows\Microsoft.NET\Framework\
  2. While holding the shift key down, right click on the folder called "v2.0.50727".
  3. You will see the normal context menu but with an extra option called "Command Window Here"

Getting the command window open (Older versions of Windows)

  1. Click the start button, select Run.
  2. Type "cmd" without the speech marks and press enter
  3. Copy this line of text: cd C:\Windows\Microsoft.NET\Framework\v2.0.50727\
  4. Right click in the command prompt window and choose paste.
  5. Press enter

Setting up the database

Now that you are in the correct location you should type the text below into the command line.

aspnet_regsql.exe -E -S .\SQLEXPRESS -A mrp -d databasename

The -E, -S, -A and -d are all case-sensitive so make sure you type the line exactly!

Replace SQLEXPRESS with the instance name of your database server - if you're using the free version of Sql Server then you will almost certainly be called .\SQLEXPRESS. The .\ bit at the start means "this computer" so if your sql server is on a different server then put the computer name there such as COMPUTER\SQLEXPRESS.

Replace databasename with the name of the database you want to add these features to.

What do the command line parameters mean?

You can get a full explanation of all the options available by typing:

aspnet_regsql -?

Here is a run down of the parameters we used:

-E Auth with windows credentials -S server instance -A services to add (membership, roles, profiles) -d database name

REMEMBER - Parameters are case sensitive

Did it work?

Press enter and you should see this:

Start adding the following features:
Membership
Profile
RoleManager

.......

Finished.

C:\Windows\Microsoft.NET\Framework\v2.0.50727>

A final tip

One thing that I did not realise the first time I used these features is that you can use an existing database when you set these tables up. In my first site that I used these features I ended up with two databases like ClientDatabase and ClientDatabaseAspNetDB because I thought that it would overwrite my data! This is NOT the case! You can specify the same database you are using for all your other development.

Further Reading

kick it Shout it vote it on WebDevVote.com

3 comments :

Golda said...

Thanks for the tip.

Kobie Williams said...

Helped a lot.

Zanyar Ebrahimi said...

Thank you so much. it was really helpful. I have shared IP server and this post solved my problem to have a nonautomated membership database.