The connection name 'DefaultConnection' was not found in the applications configuration or the connection string is empty.

Dec 3, 2012 at 9:29 PM

I am brand new to coding, so please let me know if there is additional information that I can provide to help troubleshoot my problem.

I am currently receiving the following error when I attempt to run the ASP.NET Configuration > Security as described on page 82 and 83 of the pdf guide:

There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store. 

The following message may help in diagnosing the problem: The connection name 'DefaultConnection' was not found in the applications configuration or the connection string is empty. (C:\Users\Nick\Documents\Visual Studio 2012\Projects\MVCStoreTestWebApp\MVCStoreTestWebApp\web.config line 43)

So far, I have followed the instructions exactly, and short of a few variances between VS2010 and VS2012, I haven't had any issues.

Please let me know what I can do to resolve this issue or let me know what additional information I can provide.

Thanks!  - Nick

Dec 5, 2012 at 1:18 PM

I haven't gotten a response yet, so I thought I would add some more detail.  I'm currently running VS2012 Ultimate and SQLServer 2012.

In the web.config, I had to modify what was in the guide to the following in order to get it to work:

<connectionStrings>
    <add name="MusicStoreEntities"
         connectionString="Data Source=davinci-vostro;Initial Catalog=MvcMusicStore;Integrated Security=True"
         providerName="System.Data.SqlClient" />
</connectionStrings>

I don't believe there is much else that I have changed from the guide.  I've tried changing 'DefaultConnection' to 'local' and 'localhost' without success.  I've done my googling about the problem, but I can't find a solution.

Any help would be greatly appreciated.

Thanks! - Nick

Dec 7, 2012 at 2:59 PM

Hi Nick,

I also stumbled into this one. Also running Visual Studio 2012 if that could be relevant.

Anyhow, to get this working we also need to update the web.config file with appropriate connection details to where the the user data is to be stored. First follow the part of the tutorial creating another project which is not initially empty. From this one you can copy the row with default connection string (named DefaultConnection).

I also had some issues with getting it working with the artifacts for the Account-stuff. I would advice you to copy those as well from the project created above - and remember to change the namespace in each file (it is just one place in each).

Good luck!

/Henrik

Dec 7, 2012 at 4:02 PM
Edited Dec 7, 2012 at 4:15 PM

Thanks so much for the response!  I've been banging my head against the wall trying to figure this out.  I'm new at this, so I'm having some trouble following your instructions.  Here are my two web.config files.  Can you help me determine what needs to change?  Thanks!

MVCStoreWebApp - web.config: This is the file that needs to change.

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
    <httpRuntime targetFramework="4.5" />
    <profile defaultProvider="DefaultProfileProvider">
      <providers>
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </profile>
    <membership>
      <providers>
        <add connectionStringName="DefaultConnection" enablePasswordRetrieval="false"
          enablePasswordReset="true" requiresQuestionAndAnswer="false"
          requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6"
          minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
          applicationName="/" name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </providers>
    </membership>
    <roleManager>
      <providers>
        <add connectionStringName="DefaultConnection" applicationName="/"
          name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </providers>
    </roleManager>
    <!--
            If you are deploying to a cloud environment that has multiple web server instances,
            you should change session state mode from "InProc" to "Custom". In addition,
            change the connection string named "DefaultConnection" to connect to an instance
            of SQL Server (including SQL Azure and SQL  Compact) instead of to SQL Server Express.
      -->
    <sessionState mode="Custom" customProvider="DefaultSessionProvider">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
      </providers>
    </sessionState>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
  <connectionStrings>
    <add name="MusicStoreEntities"
         connectionString="Data Source=davinci-vostro;Initial Catalog=MvcMusicStore;Integrated Security=True"
         providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

 

 

TestWebApp - web.config: This is the project that I created as outlined in your comment above.

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->
<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
    <httpRuntime targetFramework="4.5" />
    <profile defaultProvider="DefaultProfileProvider">
      <providers>
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </profile>
    <membership defaultProvider="DefaultMembershipProvider">
      <providers>
        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <roleManager defaultProvider="DefaultRoleProvider">
      <providers>
        <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </roleManager>
    <!--
            If you are deploying to a cloud environment that has multiple web server instances,
            you should change session state mode from "InProc" to "Custom". In addition,
            change the connection string named "DefaultConnection" to connect to an instance
            of SQL Server (including SQL Azure and SQL  Compact) instead of to SQL Server Express.
      -->
    <sessionState mode="InProc" customProvider="DefaultSessionProvider">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
      </providers>
    </sessionState>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
  <connectionStrings>
    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-TEST2-20121207115144;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-TEST2-20121207115144.mdf" />
  </connectionStrings>
</configuration>
Dec 8, 2012 at 5:56 PM
Edited Dec 8, 2012 at 5:59 PM

Hi again,

you should ONLY make adjustment within your web.config file inside the <connectionStrings> block.

Inside the project you already got working (the one without working login function) you can simply copy this segment from what you posted:

<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-TEST2-20121207115144;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-TEST2-20121207115144.mdf" />

The result should be a <connectionStrings> block with TWO <add> tags (one for your mvc store data and and for the user login data), like this:

<connectionStrings>
  <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-TEST2-20121207115144;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-TEST2-20121207115144.mdf" />
  <add name="MusicStoreEntities" connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf" providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>

Dec 11, 2012 at 1:05 PM

Thanks!  That was the problem.  The instructions don't make it clear that you have two add tags inside of one connectionstring.

Thanks for your time.

Apr 25, 2013 at 10:04 PM
Hi.
I added the new 'add' tag but I'm having exactly the same issue. What do I need to do to fix this? Thank you.
Jan 21, 2014 at 7:49 AM
Hey! I had the same problem as nicholastjohnson ,but wyzec's answer made the error go away. I think at the beginning of the code creation I deleted the defaultConnectionString. So I had again replace the code segment. It actually worked for me and the security link appears successfully. Thank you for the help and thanks nicholastjohnson for asking this question because I was about to bang my head in the wall in the next few minutes but your question saved my time and head. Thanks again.
Jan 27, 2014 at 2:40 AM
Hi. I've also have this problem, but this problem you can easy solve. I don't know if you use mvc3 or 4, i'm using mvc 4.
Every DefaultConnection string replace with the name of the class i.e for this app MusicStoreEntities. Also in the last row of <add tag there is also attribute called name, so the value of this attribute name will have to be also MusicStoreEntities. If again you have this problem in the administration panel just find the next tag where the error tells you and repeat the same replacing.

Here is my example:
 <add connectionStringName="MusicStoreEntities" enablePasswordRetrieval="false"
          enablePasswordReset="true" requiresQuestionAndAnswer="false"
          requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6"
          minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
          applicationName="/" name="MusicStoreEntities" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
Mar 2, 2014 at 1:50 PM
wyzec solution works.......thank you
Apr 24, 2014 at 12:01 PM
This is very helpful, thank you for the post.