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?

5
  • 1
    Without the actual value of database_server_name it is just a guessing game. Commented Apr 23, 2023 at 16:11
  • first thing first, from the server that hosts the shared folder ping the My Sql server either with IP or DNS. does it respond ? Commented Apr 23, 2023 at 16:11
  • @jmvcollaborator how to ping from the server that hosts the shared folder please ? i don't have access to that server via remote connection but i have access to the shared folder Commented Apr 23, 2023 at 16:30
  • The following may be helpful: stackoverflow.com/a/71199793/10024425 Commented Apr 23, 2023 at 16:31
  • System.ComponentModel.Win32Exception (5): Access denied. seems to be the key here Commented Apr 23, 2023 at 19:43

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Named pipes work between machines, no? Microsoft seem to think so... learn.microsoft.com/en-us/windows/win32/ipc/named-pipes
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.