Click here to Skip to main content
15,560,073 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi. I have made a simple app that includes SQL Server database. App is working perfectly on my PC, but ,when I copy project on another PC and try to run the app, the error comes up:

Cannot connect to

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) (Microsoft SQL Server, Error: 1326)

This is my connection string:

private string connString = @"Data Source=JOHN-PC\SQLEXPRESS;Initial Catalog=ProfessorDatabase;Integrated Security=True;Pooling=False";

This is driving me crazy.

What I have tried:

So far I tried enabling TCP/IP for my server name,I added inbound and outbound rules in Firewall on both PCs. Please help me.
Updated 26-Feb-16 9:08am
Jochen Arndt 26-Feb-16 6:52am    
This is usually sourced by a firewall blocking the connect. Note that there may be multiple firewalls between the server and the client. Start with those on the server system (you may install the client there or inside the local sub-net and try connecting using the IP of the server's network interface). Then check the firewall settings on the next router (e.g. the internet gateway).

If this does not help do the same on the client side but for outgoing packets.
ZurdoDev 26-Feb-16 7:40am    
The error is clear, "Cannot connect to" You need to troubleshoot why.
Richard Deeming 26-Feb-16 8:57am    
Be careful with the firewall configuration - that seems to be a public IP address. You don't want to leave your SQL instance open to the whole world!
PeMaCN 26-Feb-16 14:09pm    
I improved my question

1 solution

Did you remember to add the instance name also in the connection ???

and yes check the firewall settings or turn it off for testing purpose.
Share this answer
PeMaCN 27-Feb-16 7:54am    
Thanks for reply. I turned off firewall on my PC and then when I tried to run the app on another PC I got this error: Login failed.The login is from an untrusted domain and cannot be used with Windows authentification.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900