View Single Post
  #1 (permalink)  
Old March 3rd, 2008, 03:43 AM
hertendreef hertendreef is offline
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