I'm trying to use the Web Site Administration Tool to configure membership for a web site on my server. I've created an aspnetdb database on my local copy of SQL Server, and through the WSAT, I've managed to add several roles, and to lock down a couple of directories on the server.

However, when I try to manage users, I get the following error:

The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty. at System.Web.Util.SecUtility.GetConnectionString(NameValueCollection config) at System.Web.Security.SqlMembershipProvider.Initialize(String name, NameValueCollection config) at System.Web.Configuration.ProvidersHelper.InstantiateProvider(ProviderSettings providerSettings, Type providerType)

Clearly, the LocalSqlServer connection string is OK, otherwise I wouldn't have been able to add the roles, for example.

The relevant parts of web.config are as follows:

  <connectionStrings>
        <clear />
        <remove name="LocalSqlServer"/>
        <add name="LocalSqlServer" connectionString="Data Source=(local);Initial Catalog=aspnetdb;User Id=LoginUser;Password=password;" providerName="System.Data.SqlClient"/>
  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" defaultUrl="~/admin/admin.aspx" />
    </authentication>
        <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
            <providers>
                <clear />
                <add
          name="SqlProvider"
          type="System.Web.Security.SqlMembershipProvider"
          connectionStringName="LocalSqlServer"
          applicationName="myapp" />
            </providers>
        </membership>
    <profile>
      <providers>
        <clear />
                <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="myapp" />
      </providers>
    </profile>
    <roleManager enabled="true">
      <providers>
        <clear />
                <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="myapp" />
      </providers>
    </roleManager>
  </system.web>

As far I understand it, the Clear/Remove elements should override any other config files, but regardless, I tried adding the same connection string to the relevant machine.config, but to no avail.

Any ideas?

As an alternative, is there any reason why I can't call the Membership DB stored procedures directly? Does anyone know of any supporting documentation?

3

There are 3 answers

0
CJM On BEST ANSWER

I scrapped as much of the initial attempt as I could and started again. This time I created a new, separate Membership DB, and I commented out all role and membership provider elements from machine.config...

This didn't solve the problem, but in the process I realised that even though I'd modified machine.config, WSAT was still picking up role provider configurations from somewhere. This led me to hit the x86 machine.config, which in turn led me back to the app pool - the app pool was set to enable 32-bit applications.

Resetting this to false enabled me to get past my error, albeit to different error instead - however, I will investigate this problem separately and create a new post if necessary.

I'm not sure why the 32-bit app pool should have caused the problem - I still would have expected that my web.config (with the <clear /> items) should have replaced all the appropriate settings inherited from machine.config - whichever version it may be. So it may be that some other part of my 'rebuild' contributed as well; it's hard to say.

Not quite the definitive resolution I hoped for, I'm afraid.

2
ForceMagic On

After some research, I've found possibles solutions for you. I think you might have read some of the thread I found, but I tried to point out the differences with the version you shown us.

In the role manager tag,

you haven't set the defaultProvider which could cause an issue.

<roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider">

See this link for more details. That was also my reference.

I also noticed

Inside your connectionString the "d" of your User ID is not upper case. Not sure if it's case sensitive.

Moreover, some thread seems to set Integrated Security= according to their needs, in the connectionString, you might try to do the same.

See this link.

Apparently,

by default, the membership / role provider uses the "localSQLServer" connection string which is [...] set to point to a local SQL Express database from the root web.config. In most cases, the server do not have SQL express installed and you will get this error.

By clearing the connection strings should reveal those errors.

Reference

But I believe you are already using the </clear> tag everywhere, which is correct.

More references

You might also want to have a look on aspnet Forums since it's their technology. I entered you error message and actually got a lot of results.

Finally

If any of those suggestions haven't solve your problem, I'd suggest to start back "from scracth" adding each config one by one. Good luck!

0
PeterHerne On

This worked for me:

  1. In Visual Studio go to the server explorer and attach the aspnetdb
  2. right click the aspnetdb - modify connection
  3. If the connection test works click "advanced"and copy the connection string at window buttom
  4. replace this connection string in your web.config/ConnectionStrings/ApplicationServices/ConnectionString