Click here to Skip to main content
15,906,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hey guys, this is the situation:
i have a pc with sql server (express) 2012 install on it.
i have a laptop and i am trying to connect to a database on the pc throug c# application on my laptop.
after manipulayting all of the settings including open port, firewalls and tcp/ip protocols, i managed to connect to the database sitting on my pc and get access to all of the tables. the problem is that i succeed doing it only when i am on the same network (same wifi) of the pc. if i move my laptop to another wifi or my cell phone will use as a hotspot, i will get this error:
An error has occurred while establishing a connection to the server


the code is preety basic:

C#
System.Data.SqlClient.SqlConnectionSqlCon SqlCon = new SqlConnection(Data Source=(the ip address),1433;integrated Security=true;Network Library=DBMSSOCN;Initial Catalog=LocalDB);
SqlCon.Open();


What I have tried:

open port 1433 the the firewall, allow remote connectivity
Posted
Updated 11-Feb-16 13:01pm
v2
Comments
PIEBALDconsult 11-Feb-16 19:03pm    
"integrated Security=true"
Do you have a domain controller that allows that?

1 solution

I'd be looking at tracing the route between the two networks that dont work - ie, its obvious when you're on the same network, but when you're on a different network, there's nothing to say 'to get from network a (eg 'another wifi or phone) to network b (the one where sql server is running on the laptop), you need to go this way'

this is the first part you need https://support.microsoft.com/en-us/kb/314868[^]

you 'may' be able to do a 'route add' on your pc to add the missing information - it may also be more complicated than that - ie, if the sql server machine & network is behind a firewall, do you have a 'public address' NAT'd to it ?

[edit - Im trying to post this here because as a comment it doesnt render well]

C#
this really depends on what network infrastructure you have/know about  - for instance 

private/internal network |firewall| DMZ |firewall| public network         OR
private/internal network |firewall| public network 

in both case's, if you're 'out' in the public network on the right hand side, and need to see a machine in the private/internal network, you may need  (looking at the simpler case)

private/internal network |firewall                                          | public network
--------------------------------------------------------------------------------------
server with                     | Firewall Rules                              |  public address 
Tcp/ip address              | and Network Address Translates|
a.b.c.d                           | eg public address e.f.g.h goes to |
                                      | a.b.c.d internally                          |

[edit : I cant draw this properly here :-( ]
 
Share this answer
 
v2
Comments
oronsultan 11-Feb-16 17:18pm    
"do you have a 'public address' NAT'd to it ?" ? I didnt understand your last q Garth...
Garth J Lancaster 11-Feb-16 17:26pm    
this really depends on what network infrastructure you have/know about - for instance

private/internal network |firewall| DMZ |firewall| public network OR
private/internal network |firewall| public network

in both case's, if you're 'out' in the public network on the right hand side, and need to see a machine in the private/internal network, you may need (looking at the simpler case)

private/internal network |firewall | public network
--------------------------------------------------------------------------------------
server with | Firewall Rules | public address
Tcp/ip address | and Network Address Translates|
a.b.c.d | eg public address e.f.g.h goes to |
| a.b.c.d internally |

[edit : I cant draw this properly here :-( ]
Garth J Lancaster 11-Feb-16 17:35pm    
see what I have tried to 'draw' in my original answer - you need to think of 3 'zones'

internal
[the firewall]
public

for a communication to come from the 'public' side to 'internal', the firewall (simplification), would usually have rules and NAT (network address translates), saying that if we had address e.f.g.h on the public side, that 'translates' (and gets routed to) a.b.c.d on the internal network

oronsultan 11-Feb-16 17:26pm    
btw, iby doing the command prompt "tracert" i get a message saying the destination host unreachable.

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