Monday, September 10, 2007

Create ASPNET Role provider schema for existing database

ASP.NET Role and profile provider is one of the best feature provided by ASP.NET 2.0.
Here ASP.NET provides you complete schema for your authorization-authentication functionality. You can customize and use this schema as well as you can use ASP.NET 2.0 Login controls which in turn use the same schema.
You can create this schema using ASP.NET website administration tool. This will create one new database named as "aspnetdb" in your local SQL instance.

But many of the times you need to update your existing database with ASP.NET Role and profile provider schema. How you can do this?? Heres the answer

"apsnet_regsql.exe" is the utility provided by MS to create this schema for you. There are serveral options available with this command line utility.
ASP.NET 2.0 provides this exe and you can find it in "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727".

For all options provided with "aspnet_regsql.exe" click here.

Suppose if you have database named as "blog_test" and you want to update it with ASP.NET role provider schema then you can do this as following

Just run following commands on command prompt.


C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_regsql.exe -S (YourServerName)\SQLEXPRESS -A all -E -d blog_test



S - Option to specify server name
A - All services, including common tables and stored procedures shared by the services
E - This will use your windows credentials for authentication. You can sepecify your username and password using "-U" and "-P" options respectively if applicable.
d - Option to specify database name. In our case it is "blog_test"

The output of this command should be


Start adding the following features:
Membership
Profile
RoleManager
Personalization
SqlWebEventProvider

..................

Finished.


Now, open your SQL Server 2005 Management studio and check newly created tables and store procedures for database "blog_test".

So your application can use the existing database with role provider schema by ASP.NET 2.0
Rock!!!

1 comment:

Neil Vats said...

Awesome Vinayak... wonderful tip...