Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 3rd, 2008, 03:43 AM
Friend of Wrox
 
Join Date: Apr 2006
Location: , , .
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

  #2 (permalink)  
Old March 3rd, 2008, 04:23 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 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
  #3 (permalink)  
Old March 8th, 2008, 05:47 AM
Friend of Wrox
 
Join Date: Apr 2006
Location: , , .
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for replying.
It works now.

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:20 PM.


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