Search code examples
c#asp.netasp.net-membershipparse-error

"The attribute 'connectionStringName' is missing or empty." in Web.config


I'm all of a sudden getting the following error with my Web.config file and I don't understand what it means:

Parser Error Message: The attribute 'connectionStringName' is missing or empty.

Line 24:       <providers>
Line 25:         <clear />
Line 26:        <add name="SMDPortalMembershipProvider" type="SMDPortalMembershipProvider" />
Line 27:       </providers>
Line 28:     </membership>

Source File: c:\inetpub\wwwroot\web.config Line: 26

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

Here's my config file:

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <connectionStrings>
    <add name="ApplicationServices"
      connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
      providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="UODOTNET, Version=2.2.5.7444,
          Culture=neutral, PublicKeyToken=335F3FBD4BE82339"/>
        <add assembly="System.Core, Version=4.0.0.0,
          Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms loginUrl="Default.aspx" timeout="2880" />
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>
    <membership defaultProvider="SMDPortalMembershipProvider">
      <providers>
        <clear />
        <add name="SMDPortalMembershipProvider" type="SMDPortalMembershipProvider" />
      </providers>
    </membership>
    <customErrors mode="Off"/>
    <sessionState cookieName="smd_portal_session" timeout="100"/>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

There is no error when I load the Default.aspx page, but as soon as my code calls upon the Membership class I'm getting the error.


Solution

  • Your membership provider's config section needs a connectionStringName attribute. Without that connectionStringName, it doesn't know what database to look for membership information in.

    You need to add the name of one of your the connection strings in the connectionStrings section to the add tag on line 26.

    The connectionStringName attribute is required in order for your Web.Config to be valid. You can't use the Membership class without it.