Today I wanted to connect to a Microsoft SQL Server (Express Edition) via a custom powershell script.
I used the sqlcmd command, supplied a username and password and tried to connect.
The script stopped with the following error:
HResult 0x2, Level 16, State 1 Named Pipes Provider: Could not open a connection to SQL Server .
Turns out that I forgot to enable the “Named Pipes” protocol. Fire up your SQL Server Configuration Manager and enable this protocol. Don’t forget to restart the service afterwards.
Have a look at the following screenshot.