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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
If you get this error, firstly check that if your database is on a separate machine, you are able to ping the machine. Especially make sure that if you are using ip address in the connectionstring for server, ping it ,you should get reply.
Also ensure your firewall is not blocking the connection
In anycase, try changing connection string (if you have options) and see if the error disappears!