How to deploy aspnetdb. MDF and connections before using user profile to store information in ASP. NET 2.0

Source: Internet
Author: User

I have taken a lot of detours while solving this problem. I will summarize the methods to you! I hope no one will think of me and it will take nine hours to complete it.

This problem may occur in both SQL Server 2005 and SQL Server Express.

Premise: When I add

<Anonymousidentification enabled = "true"/>
<Profile enabled = "true">
<Properties>
<Add name = "mynewproperty" allowanonymous = "true"/>
</Properties>
</Profile>

If it is correct

// Code in page1.aspx
Profile. mynewproperty = "hello ";

//

// Code in page2.aspx
String myproperty = profile. mynewproperty;
Access.

Problem:

After modifying web. config, an error is reported when debugging and running any pages in the project:
User code does not handle httpexception
Cannot connect to the SQL Server database.

An error is reported during direct browsing:
Do not generate user instances in SQL Server. Use sp_configure 'user instances enabled' to generate a user instance.

Find the problem by yourself and discover it again
Open an Asp.net website in vs2005-> menu bar website-> Asp. Net configuration-> provider-> aspnetsqlprovider Test
The same error also occurs.
Provider management
Failed to establish database connection. If you have not created an SQL Server database, log out of the website management tool, use the aspnet_regsql command line utility to create and configure the database, and then return to the tool to set the provider.

Run the aspnet_regsql command under the SDK to enable the wizard configuration. When selecting the server and database appears (may appear)
Failed to query the list of database names in SQL Server.
An error occurred while establishing a connection with the server.

Solution:

1.
We recommend that you first open SQL Server Management studio express to check whether a database named aspnetdb exists.

2.
If not, run the aspnet_regsql command in the SDK to enable the Wizard to generate a database.
Start --> Microsoft. net Framework SDK V2.0 --> SDK command prompt --> input aspnet_regsql --> after two next steps, enter the server name, LQB-PC \ sqlexpress, to access the database at the same time, data source = is followed by the same content. The default value does not include "\ sqlexpress". After selecting Windows authentication, click the drop-down list arrow to display several database names, click Next until the task is completed. In this way, open SQL Server Management studio express again and you will see the created aspnetdb database.

3. Use SQL Server Management studio express to create a login name aspnetsa.

Select User ing settings in this user's login attribute

Set on the server properties page

Add the aspnetsa permission to the aspnetdb attribute settings. If I am lazy, I will set all the permissions.

In this way, the user has established

4. Next, modify the connection string.
On the System Disk: \ windows \ Microsoft. NET \ framework \ <version> \ config, there are two files: Web. config and mechine. config,
One file contains such code.

<Connectionstrings>
<Add name = "localsqlserver" connectionstring = "Data Source =. /sqlexpress; Integrated Security = true; attachdbfilename = | datadirectory | aspnetdb. MDF; user instance = true "providername =" system. data. sqlclient "/>
</Connectionstrings>
The connection string needs to be modified according to your own situation, and the original format is not used. In this way, modify it.
"Data Source = LQB-PC \ sqlexpress; initial catalog = aspnetdb; Integrated Security = false; uid = aspnetsa; Pwd = xxxxxx"
5. Open an Asp.net website in vs2005 again-> menu bar website-> Asp. Net configuration-> provider-> aspnetsqlprovider Test
This should occur: the connection to the database has been established successfully. If it succeeds, congratulations! If the connection fails, go back to Step 3 and modify the permissions of aspnetsa according to the error prompt, and check whether your connection string is wrong.

6. Now let's take a simple example to test it:

Create an Asp.net website in vs2005, debug it first, and close it. A Web. config file is displayed in the project.
</System. Web>
</Configuration>
Add
<Anonymousidentification enabled = "true"/>
<Profile enabled = "true">
<Properties>
<Add name = "mynewproperty" allowanonymous = "true"/>
</Properties>
</Profile> Save.

Drag a label (ID: resultlabel) and a button (ID: okbutton) in default. aspx. The modification code is as follows:
Protected void page_load (Object sender, eventargs E)
{
If (page. ispostback = false)
{
Profile. mynewproperty = "red ";
}
}
Protected void okbutton_click (Object sender, eventargs E)
{
Resultlabel. Text = profile. mynewproperty;
}
Debug and run. If you do not see the two red-letter errors at the beginning of this article, you have configured them. Then, click the button to display red and congratulations in the tag!

Source: http://www.cnblogs.com/lqb

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.