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?
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.