Fix – The connection name ‘LocalSqlServer’ was not found in the applications configuration or the connection string is empty

Imagine you are struck when you see the error message – The connection name ‘LocalSqlServer’ was not found in the applications configuration or the connection string is empty. Don’t Panic. You can easily fix the error and happily run the like any other ASP.NET application.

Web hosting providers follow different rules for configuring ASP.NET on the servers. While most of the applications can be hosted using the default settings, some applications throws errors and exceptions. If you are not experienced with ASP.NET then you will face difficulties to fix the problem unless your web hosting provider helps you to resolve the issue. In this article, I will examine how to fix an ASP.NET error which occurs rarely while deploying an ASP.NET 3.5 application to a web hosting server.

The error message will be as you will see 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 ‘LocalSqlServer’ was not found in the applications configuration or the connection string is empty

Source Error:

Line 160:        <roleManager>
Line 161:        <providers>
Line 162:    <add name=”AspNetSqlRoleProvider” connectionStringName=”LocalSqlServer” applicationName=”/” type=”System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”/>
Line 163:        <add name=”AspNetWindowsTokenRoleProvider” applicationName=”/” type=”System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”/>
Line 164:

Source File: <PATH_DELETED>\Config\machine.config    Line: 162

——————————————————————————–
Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.4049

Resolution

The above error message indicates that connection string names LocalSqlServer is being used in the machine.config file. You have to override this setting to point to your connection string name which is used in the application’s web.config file.

This can be done by clearing, removing and adding connection string name in your web.config file as shown below.

<connectionStrings>
<clear />
<remove name=”LocalSqlServer ” />
<add name=”LocalSqlServer” connectionString=”Server=SQL_SERVER_HOST; User ID=YOUR_USER_NAME;password=YOUR_PASSWORD;Database=YOUR_DATABASE_NAME;Persist Security Info=False” providerName=”System.Data.SqlClient” />
<add name=”ASPNETDBConnectionString” connectionString=”Server=SQL_SERVER_HOST; User ID=YOUR_USER_NAME;password=YOUR_PASSWORD;Database=YOUR_DATABASE_NAME;Persist Security Info=False” providerName=”System.Data.SqlClient” />
</connectionStrings>

Add the above code to your web.config file, update the variables mentioned in capital letters and upload to your web server. Your application should work fine now.

One Response

Leave a Comment