远程连接到SQL Server [英] Connect remotely to sql server

查看:100
本文介绍了远程连接到SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,这就是情况:

我有一台带有sql server(express)2012安装的电脑。

我有一台笔记本电脑,我正试图通过我的笔记本电脑上的c#应用程序连接到PC上的数据库。

在操作包括开放端口,防火墙和tcp / ip协议在内的所有设置后,我设法连接到我的电脑上的数据库并访问所有表。问题是,只有当我在电脑的同一网络(相同的wifi)上时才能成功。如果我将我的笔记本电脑移动到另一个wifi或我的手机将用作热点,我将收到此错误:

建立与该连接的连接时发生错误服务器





代码基本可靠:



 System.Data.SqlClient.SqlConnectionSqlCon SqlCon =  new  SqlConnection(数据源=(IP地址), 1433 ;集成安全性=  true ;网络库= DBMSSOCN;初始目录= LocalDB); 
SqlCon.Open();





我尝试过:



打开防火墙端口1433,允许远程连接

解决方案

我正在寻找跟踪两者之间的路线不工作的网络 - 也就是说,当你在同一个网络上时很明显,但当你在不同的网络上时,没有什么可说的'从网络a(例如'另一个wifi或电话)到网络b(在笔记本电脑上运行sql server的那个,你需要这样'



这是你需要的第一部分https://support.microsoft.com/en-us/kb/314868 [ ^ ]



你'可能'是能够在你的电脑上做一个'路由添加'来添加缺少的信息 - 它也可能比那更复杂 - 即,如果sql server machin电子邮件网络是在防火墙后面,你有一个NAT公共地址吗?







 这个真的取决于你的网络基础设施有/知道 -   实例

私人/内部网络|防火墙| DMZ |防火墙| public network OR
private / internal network | firewall | public network

case ' s,如果你重新 ' out' public 网络在右侧,需要在私人/内部网络中查看 ,您可能需要(查看更简单的 case

private / internal network | firewall | public network
------------------------------ -------------------------------------------------- ------
服务器带|防火墙规则| public 地址
Tcp / ip地址|和网络地址翻译|
a.b.c.d |例如 public 地址e.f.g.h转到|
| a.b.c.d内部|


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:

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

解决方案

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]

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 :-( ]


这篇关于远程连接到SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆