ASP. NET 2.0 User Management Database Registration

Source: Internet
Author: User
Tags connectionstrings
ArticleDirectory
    • 1. Create a table
    • 2. Set the connection string

Many new features are provided in ASP. NET 2.0, which require the use of providers to provide access to the database. With the provider, you can manage users and roles without writing ADO. Net to access the database.

To use new features such as user management provided by. NET 2.0, you must first create the corresponding table in the database and set the appropriate database connection string.

1. Create a table

ASP. NET 2.0 requires 11 tables for user and role management. These tables can be added to an existing database or a new database.

Generally, this parameter is set to aspnet_regsql.exe.ProgramTo complete database registration. The procedure is as follows:

(1) Run "C: \ WINDOWS \ Microsoft. NET \ framework \ v2.0.50727 \ aspnet_regsql.exe". The Wizard dialog box shown is displayed.

(2) Click "Next". In the displayed dialog box, select the first radio button to configure the database.

(3) In the following dialog box, enter the name of the database server. In the "Database" section below, select the database to which the 11 tables need to be added. If "default" is used, a database named "aspnetdb" is created and stored on SQL Server by default.

(4) Click "Next" twice to display the displayed dialog box to complete database creation or modification.

(5) open management studio of SQL Server and expand the newly created or modified database. The following 11 tables are added, which are used to save user and role information respectively.

(6) The following stored procedures are also displayed in the database storage process.

(7) How does the system create these 11 tables and more stored procedures? In fact, in "C: \ WINDOWS \ Microsoft. NET

\ Framework \ v2.0.50727 "contains the following SQL files.CodeYou can also create tables and stored procedures.

2. Set the connection string

After creating a suitable database (or adding tables to the original database), the system cannot access the database normally. In this case, you also need to modify the connection string in Web. config so that the application can correctly connect to the database.

The simplest way is to modify web. config in the website root file, add the following connection string to the file, and connect to the database created or modified earlier.

<Connectionstrings>
<Remove name = "localsqlserver"/>
<Add name = "localsqlserver" connectionstring = "Data Source =.; initial catalog = aspnetdb; uid = sa; Pwd = ;"
Providername = "system. Data. sqlclient"/>
</Connectionstrings>

Use remove to remove the connection string named "localsqlserver.

You can also add the connection code to the Web. config file through settings in the IIS management tool. The generated code is as follows:

<Remove name = "localsqlserver"/>

<Add name = "localsqlserver" connectionstring = "Data Source =.; Integrated Security = sspi; attachdbfilename = | datadirectory | aspnetdb. MDF; user instance = true"

Providername = "system. Data. sqlclient"/>

 

In the above Code, use attachdbfilename to connect to the database. This parameter can be used in SQL Server 2005 express to specify the database.

 

After the above two steps, you have completed the database addition (or modification) and registration operations, and then you can use the "ASP.. Net website management tool.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.