How can I fix error 40 when connecting local server in sql Server

This is the error that ne comes out:

TITLE: Connect to Server
------------------------------

Cannot connect to DESKTOP-1N1OK6F.

------------------------------
ADDITIONAL INFORMATION:

Error relacionado con la red o específico de la instancia mientras se
establecía una conexión con el servidor SQL Server. 

No se encontró el servidor o éste no estaba accesible. 
Compruebe que el nombre de la instancia es correcto 
y que SQL Server está configurado para admitir conexiones remotas. 

(provider: Named Pipes Provider, error: 40 - No se pudo abrir una 
 conexión con SQL Server) (Microsoft SQL Server, Error: 2)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=2&LinkId=20476

------------------------------

El sistema no puede encontrar el archivo especificado

------------------------------
BUTTONS:

OK
------------------------------
 9
Author: Carlos Muñoz, 2016-01-25

3 answers

You are trying to connect using the protocol Named Pipes which is disabled by default.

Solution:

  1. go to Sql Server Configuration Manager
  2. expands SQL Server Network Configuration
  3. Click Protocols for MSSQLSERVER
  4. right-click Named Pipes
  5. Enable
  6. restart the service

Enable Named Pipes

 5
Author: Carlos Muñoz, 2016-01-29 00:47:27

This error is very common and very easy to fix: you just have to activate the "SQL Server" and "SQL Server" services in the "Sql Server Configuration Manager". I leave you some pictures:

enter the description of the image here

Hope solve your problem.

Greetings!

 3
Author: Eduardo Munizaga, 2016-01-29 00:41:27

Consider using backslash in the connection string.

Incorrect:

var conexion = "Data Source=Maquina/instancia..";

Correct:

var conexion = @"Data Source=Maquina\instancia..";
 0
Author: Einer, 2017-07-20 19:39:45