-->

The connection name 'DefaultConnection' wa

2019-08-08 21:49发布

问题:

I just started getting this message when I run my ASP.NET MVC 4 application in debug mode in Visual Studio 2010 Professional in the internal development server. It was working fine till yesterday. It just started coming yesterday.

Also, this error comes only on my desktop. The application runs fine on all the other developer's machines, my laptop, and all the servers, both in debug mode as well as when deployed on IIS.

The actual error I get in the yellow screen of death is given below:

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

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

Source Error:

Line 267:    <membership defaultProvider="DefaultMembershipProvider">
Line 268:      <providers>
Line 269:        <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="/" />
Line 270:      </providers>
Line 271:    </membership>

I checked the version history of my web.config in TFS and there isn't and there also never used to be a connection string by that name DefaultConnection ever.

回答1:

Add this to your web.config file

<connectionStrings><add name="DefaultConnection" connectionString="Data Source=YourServername;Initial Catalog=YourDBname;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /></connectionStrings>


回答2:

Only thing I can think of is you can browse the public pages without proper membership connection string. However, as soon as you browser pages which require authentication, it will fail.

It should work if you replace DefaultConnection with working connection string.