Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2008, 03:43 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default error in web.config when using roles

Hi,

When the application doesn't use Roles, this configuration (web.config) works:

<configuration>
<connectionStrings>
<clear/>
<add name="myconn" connectionString="Data Source=.\sqlexpress;Initial Catalog=mydb;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

...
<membership>
<providers>
<remove name="AspNetSqlMembershipProvider"/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="myconn" />
</providers>
</membership>
...

When i use Roles with this web.config:
------------------------------------------------------
<configuration>
<connectionStrings>
<clear/>
<add name="myconn" connectionString="Data Source=.\sqlexpress;Initial Catalog=mydb;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
     <authorization>
      <allow roles="role1"/>
      <allow roles="role2"/>
     </authorization>
    <roleManager enabled="true">
      <providers>
      </providers>
    </roleManager>
...
<membership>
<providers>
<remove name="AspNetSqlMembershipProvider"/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="myconn" />
</providers>
</membership>
...

I get this error: "The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty"
line 149: <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" ...

Source File: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Conf ig\machine.config line 149

I solved this by adding in web.config this line: <add name="LocalSqlServer" connectionString="Data Source=.\sqlexpress;Initial Catalog=mydb;Integrated Security=True" providerName="System.Data.SqlClient"/>

But i would like understand what happened.
Why do i have to add the second connectionString "LocalSqlServer" only when using Roles? Whats' the meaning of that error in machine.config?

Thanks

Hertendreef

 
Old March 3rd, 2008, 04:23 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The ASP.NET Application Services by default use a connection string called LocalSqlServer that looks for an ASPNETDB.mdf file in the App_Data folder. This means that Membership, Roles and Profile all make use of this connection. In your config file, you changed the behavior for Membership like this:

<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="myconn" />

With this change, the Membership provider uses the myconn connection string, but the RoleManager doesn't yet. In order to tell the RoleManager to use myconn as well you need to override its settings as well like this:

<roleManager defaultProvider="SqlProvider"
  .. other attributes go here
>
  <providers>
    <add
      name="SqlProvider"
      type="System.Web.Security.SqlRoleProvider"
      connectionStringName="myconn"
  />
  </providers>
</roleManager>

This changes the RoleManager and sets Sqlprovider as the new default provider. Alternatively, you could remove and readd the standard settings for RoleManager, just like you do with Membership. The machine.config file on your machine (at C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONF IG) defines the default behavior for these providers.

Hope this sheds some light....

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old March 8th, 2008, 05:47 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for replying.
It works now.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in Web.config.. ashokparchuri General .NET 10 April 30th, 2011 05:14 AM
VB: web.config error Rich57 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 October 12th, 2007 06:27 AM
web.config error koco ASP.NET 2.0 Basics 1 February 16th, 2007 12:04 PM
error at web.config aynajus BOOK: ASP.NET Website Programming Problem-Design-Solution 2 August 16th, 2006 03:24 AM
Web.config error ashokparchuri General .NET 4 June 28th, 2005 04:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.