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