A network-related or instance-specific error


Sponsored Links

73058_New Scooba® 230 Floor Washing Robot + Free Shipping!

 

A network-related or instance-specific error.

Here we look briefly at the error message: A network-related or instance-specific error

Here is the full error message:


A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)


I didn't really want to be spending my time on a Sunday afternoon just scratching my head over this error, but I finally got a clue after some moderate searching on the net, and it was hidden away in amongst the range of potential fixes, so I'm just listing it here so it may hopefully help someone else who is in the same specific situation.

Visual Studio 2010 New Project - ASP.NET Web Application

My current PC is fairly new and I hadn't done much dev work on it yet. I'm using Visual Studio 2010 Express with SQL Server 2008 Express and SQL Server 2012 Express. An older project could connect fine with the database. I tried using this same connection in my new project which is the one with the error, but no change. I was starting to find it quite difficult to find any debug info to help me.

Even more specific to my situation, is that as I'd selected this new project type, Membership, Roles and Profiles had been enabled by default. The earlier working project only had Membership enabled. The difference it came down to is the default use of the connection string 'LocalSQLServer'.

So my fix for getting past this error (at least), is to put the below code into the web.config of the application:


<remove name="LocalSQLServer" />


So this cancels out any default settings for the connection string 'LocalSQLServer' which could be set in the machine.config for instance or any other web.config which has priority in the config file hierarchy. Now I can move onto the next error I've got which is clearly a problem with my connection string.