Click here to Skip to main content
13,353,706 members (58,516 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


10 bookmarked
Posted 10 Nov 2010

How to create Aspnetdb database

, 13 Nov 2010
Rate this:
Please Sign up or sign in to vote.
This tip describes a shorter way to create the aspnetdb schema on your database instead of using aspnet_regsql command

Microsoft has introduced its default database schema which is served as a role provider, membership provider and profile provider in .NET 2+.
In .NET 4, the database is created automatically, and is added to your App_Data folder and an appropriate connection string will be added to your web.config. But to be able to use this feature in previous versions of .NET, you have to create the database yourself and configure your web.config to point to that database.
For the web.config part, you have to add the following part to it:

    <remove name="LocalSqlServer" />
    <add name="LocalSqlServer" connectionString="Data Source=SERVER_NAME;Initial Catalog=DATABASE_NAME;Integrated Security=True"

      providerName="System.Data.SqlClient" />

where SERVER_NAME and DATABASE_NAME should be replaced by your server/database name.
But how do you create the database with the default ASP.NET membership schema? The first solution is that you can use the aspnet_regsql command. A step by step tutorial can be found at[^]
But as far as I can remember, this command tool was a bit tricky for me and didn't always work as expected especially if you have more than one website in your dev machine that uses Aspnetdb. So I searched for a better solution and here it is:

1- Create your database in SQL server.
2- Open up your ASP.NET website in which you'd like to use ASP.NET membership features.
3- Add the following using (or imports in case of VB) directive to your default.aspc.cs (or .vb)
using System.Web.Management;

4- In the load event of your website, add the following method call:
System.Web.Management.SqlServices.Install("YOUR_SERVER", "YOUR_DATABASE", SqlFeatures.All);

Just replace the SERVER_NAME and DATABASE with the appropriate values.
Also, if you're using SQL Express edition, there's an overload for that as well:

System.Web.Management.SqlServices.Install("YOUR_DATABASE", SqlFeatures.All, "YOUR_CONNECTION_STRING");

Now fire up your site and navigate to default.aspx. The code gets executed and if you open your database in SSMS, you'll see that default scripts have been executed on your database to create the default database for ASP.NET 2.0 web applications. You can now delete the command from your page's load event.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Chief Technology Officer Banicomm
Iran (Islamic Republic of) Iran (Islamic Republic of)
Microsoft Visual Studio .NET Application Programmer, Web Developer. I'm also part of YetAnotherForum's (YAF) Development Team.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Rob Branaghan30-Dec-16 4:36
memberRob Branaghan30-Dec-16 4:36 
GeneralCan be customize tables name Pin
Vijay Tanwar12-Feb-14 23:23
memberVijay Tanwar12-Feb-14 23:23 
GeneralMy vote of 5 Pin
manumohan.ppn2-Mar-13 4:24
membermanumohan.ppn2-Mar-13 4:24 
GeneralWish I'd seen this earlier Pin
jaimepremy13-Jul-12 18:46
memberjaimepremy13-Jul-12 18:46 
GeneralReason for my vote of 3 this article needs to Pin
Scofield Puzzle17-Nov-10 23:35
memberScofield Puzzle17-Nov-10 23:35 
GeneralGlad this could help you joseph. And thanks for your vote. Pin
Kamyar16-Nov-10 4:18
memberKamyar16-Nov-10 4:18 
Glad this could help you joseph. And thanks for your vote.
GeneralReason for my vote of 5 So much easier than digging for that... Pin
joseph donley15-Nov-10 18:08
memberjoseph donley15-Nov-10 18:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 13 Nov 2010
Article Copyright 2010 by Kamyar
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid