asp.net configuration failed to connect to database in Vs2010+silverlight4

Source: Internet
Author: User
Tags command line connect sql server express

When I used VS2010+SILVERLIGHT4 to experience the role management functions of Silverlight, but the problem of not connecting to the database in ASP.net, it took me half a day to figure it out and now share my solution:

1. First make sure that your machine is installed with SQL Server Express or SQL Server 2008 Express, I did not install the SQL Server 2008 Express when I first installed vs2010, and then reinstall it.

2. Using Aspnet_regsql.exe to register a database, the tool is entered at the command line under the C:\Windows\Microsoft.NET\Framework\v4.0.30128 file C:\Windows\ microsoft.net\framework\v4.0.30128 \aspnet_regsql.exe then always next, it will use the default database name to create a database, the name is ASPNETDB;

3. Then open the VS tools-connect to Databas option, then select your native database instance name, I am using SQL Server Authentication, then select the database that you just created, then click the Advance option to copy the database connection string.

4. Open the web.config of the website, add a database connection string inside, the connection string is just get. Note that your password is followed by: similar to the following:

<add connectionstring= "Data source=win-66hvjvuseac;initial catalog=aspnetdb; User id=sa;password=123 "name=" AspNetDB "/>

5. Add the following configuration under the system.web node:

<rolemanager enabled= "true" >
<providers>
<clear/>
<add connectionstringname= "AspNetDB" applicationname= "name=" AspNetSqlRoleProvider "type=" System.Web.Security.SqlRoleProvider, system.web, version=4.0.0.0, Culture=neutral, publickeytoken=b03f5f7f11d50a3a "/>
</providers>

</roleManager>
<membership defaultprovider= "AspNetSqlMembershipProvider" userisonlinetimewindow= "hashAlgorithmType=" ">
<providers>
<clear/>
<add connectionstringname= "AspNetDB" enablepasswordreset= "true" requiresquestionandanswer= "true" Applicationname= "/" requiresuniqueemail= "false" passwordformat= "hashed" maxinvalidpasswordattempts= "5"  Minrequiredpasswordlength= "7" minrequirednonalphanumericcharacters= "1" passwordattemptwindow= "10" passwordstrengthregularexpression= "" Name= "AspNetSqlMembershipProvider" type= " System.Web.Security.SqlMembershipProvider, system.web, version=4.0.0.0, Culture=neutral, publickeytoken= b03f5f7f11d50a3a "/>
</providers>
</membership>

6. Then open IIS, modify the database connection under the Default Web site of IIS, locate the connection string named LocalSqlServer, and modify the connection string to the connection string that you just added in the configuration file

Since then, your asp.net configuration should be able to connect to the database.

You do not have to use the default name when registering the database, you can also specify an existing database to register

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.