0

I built a C# console app that connects to a SQL Server database. Locally it's working perfectly, but when I publish it to a network shared folder, I get this error:

Unhandled exception. System.Data.SqlClient.SqlException (0x80131904): 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)

System.ComponentModel.Win32Exception (5): Access denied.

The connection string used :

SqlConnection conn = new SqlConnection("Data Source=frpardb9354;Initial Catalog=" + database_source + ";Integrated Security=SSPI");

I tried using Integrated security=False and hardcoding the user ID and password, it didn't work.

I also verified that connection mode is Windows auth and SQL Server in SSMS, and that the server allows remote connection.

Anybody has an idea of the source of this error?

1 Answers1

2

According to the error message you use "Named Pipes" to connect to the database server. "Named Pipes" are a mechanism to communicate between processes on one computer. Setup your database connection to use tcp/ip instead und specify a computer name for the connection that is visible from everywhere in the local network.

Also make sure that the SQL Server is configured to allow connections from different computers and enable Firewall exemptions on the computer to allow inbound connections to Microsoft SQL.

NineBerry
  • 26,306
  • 3
  • 62
  • 93
  • Named pipes work between machines, no? Microsoft seem to think so... https://learn.microsoft.com/en-us/windows/win32/ipc/named-pipes – Marc Gravell Apr 23 '23 at 16:46
  • 1
    Using named pipes across computers will be blocked by current firewalls. You can't unblock individual named pipes, only all or none. So using them for communication between different computers is not a good idea. – NineBerry Apr 24 '23 at 00:14