Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix the "The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty." error?

I have an ASP.NET project using SQL Server CE 4.0 with Entity Framework 4.0. It works fine on my local computer.

When I move it to the remote server, however, and try to log in to the admin part of the program, I get the following error:

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

It references the following line in the machine.config on the remote server:

Line 237:    <membership>
Line 238:      <providers>
Line 239:        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
Line 240:      </providers>
Line 241:    </membership>

Now, it's true I don't have an "AspNetSqlMembershipProvider" statement in my web.config that references a connection string called "LocalSqlServer". Instead I have the following:

<membership defaultProvider="DefaultMembershipProvider">
  <providers>
    <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider" connectionStringName="PUGConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" applicationName="/" />
  </providers>
</membership>

This actually works locally. The name of the connection string is PUGConnection, not LocalSqlServer.

Why would this work locally, and not remotely? (The remote server is a shared server -- I don't have access to the machine.config.)

If I change the name of the connection string to LocalSqlServer, will it work? And if so, why would it work the other way on my local computer? The machine.config on my local computer looks the same as the one on the remote server, as far as I can tell.

like image 925
Cynthia Avatar asked Jul 26 '12 21:07

Cynthia


2 Answers

You need to remove it from your config:

<remove name="AspNetSqlMembershipProvider" />

Or, better yet,

<clear />
like image 158
SLaks Avatar answered Oct 16 '22 15:10

SLaks


You could also try to add the connection string to your config file. Even if it is not used, it should fix the errors that appear by referencing it elsewhere in the config.

<connectionStrings>
    <add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>

This is usually between the appSettings and system.data tags.

like image 34
Krisztián Balla Avatar answered Oct 16 '22 16:10

Krisztián Balla