In this article, we will explain step by step how to connect remotely to a SQL Server Express instance. Remote access is the ability to get access to a SQL Server from a remote distance in order to manipulate data which are located on that SQL Server.

在本文中,我们将逐步解释如何远程连接到SQL Server Express实例。 远程访问是一种能够远程访问SQL Server以便处理位于该SQL Server上的数据的能力。

There are two types of adjustments which must be set before connecting to the remote SQL Server. These settings are important because without them the connection to the remote SQL Server will not be able to be successfully created

连接到远程SQL Server之前,必须设置两种调整类型。 这些设置很重要,因为没有它们,将无法成功创建到远程SQL Server的连接。

Configuration settings:

配置设置:

  1. The SQL Server instance to allow the protocol being requested SQL Server实例以允许请求协议
  2. Allow access through the Window Firewall 允许通过窗口防火墙访问

In order to allow access to SQL Server instance, we have to enable TCP/IP protocol which is not enabled by default. TCP/IP (Transmission Control Protocol/Internet Protocol) is a set of protocols developed to allow networked computers to share resources over the network. It was developed by DARPA under the ARPANET in the early 1970s.

为了允许访问SQL Server实例,我们必须启用默认情况下未启用的TCP / IP协议。 TCP / IP(传输控制协议 / Internet协议)是一组协议,旨在允许联网的计算机通过网络共享资源。 它是由DARPA在ARPANET下于1970年代初期开发的。

In order to establish a successful remote connection is to set up appropriate ports through the Window Firewall. In SQL Server there are two types of instances. First is a default instance and the second is a named instance. To connect to the default instance of Database Engine, or named instance that is the only instance installed on the machine, the TCP port 1433 is the only port that you need to specify.

为了建立成功的远程连接,是通过Window防火墙设置适当的端口。 在SQL Server中,有两种类型的实例。 第一个是默认实例,第二个是命名实例。 要连接到数据库引擎的默认实例或命名实例(这是计算机上安装的唯一实例),TCP端口1433是您需要指定的唯一端口。

But if you have multiple name instances installed on your machine, to connect with one of them, we must provide a port number which corresponding to appropriate instance name. By default named instance used dynamic port, which means that every time when the Database Engine starts new port number is assigned. Because of that it is difficult to configure Windows Firewall to enable access.

但是,如果您的计算机上安装了多个名称实例,要与其中之一连接,我们必须提供与适当的实例名称相对应的端口号。 默认情况下,命名实例使用动态端口,这意味着每次数据库引擎启动时都会分配新的端口号。 因此,很难配置Windows防火墙以启用访问。

In order to resolve this problem, there is a SQL Browser service, which provide the TCP port number that corresponds to the named instances. The SQL Browser services use UDP port 1434. Now we met with the basic matters relating to remote connection, let’s continue with the setup procedure.

为了解决此问题,有一个SQL Browser服务,它提供与命名实例相对应的TCP端口号。 SQL Browser服务使用UDP端口1434。现在,我们已经了解了与远程连接有关的基本问题,让我们继续设置过程。

启用TCP / IP协议 (Enabling TCP/IP protocol )

The first step is to enable TCP/IP protocol on the SQL Server service. Open the SQL Server Configuration Manager in the Configuration Tools folder under the Microsoft SQL Server folder:

第一步是在SQL Server服务上启用TCP / IP协议。 在Microsoft SQL Server文件夹下的“ 配置工具”文件夹中打开SQL Server配置管理器

From the SQL Server Network Configuration node, select the Protocols item for the appropriate SQL Server. In the details pane, right click the TCP/IP item and select the Enable option:

在“ SQL Server网络配置”节点中,为适当SQL Server选择“ 协议”项。 在详细信息窗格中,右键单击“ TCP / IP”项,然后选择“ 启用”选项:

After this step the Warning box pop up in which informs us that changes that are made won’t take effect until the next time service is started.

完成此步骤后,将弹出警告框,其中警告我们所做的更改要等到下次启动服务后才会生效。

In order for the changes take effect, from console pane, select the SQL Server Services and from the details pane, right click the SQL Server (SQLEXPRESS) database engine instance and click the Restart option:

为了使更改生效,请从控制台窗格中选择“ SQL Server服务”,然后从详细信息窗格中,右键单击“ SQL Server(SQLEXPRESS)”数据库引擎实例,然后单击“ 重新启动”选项:

Now the service started with TCP/IP enabled, but still can’t connect remotely until we configure the Windows Firewall.

现在,该服务在启用TCP / IP的情况下启动,但在配置Windows防火墙之前,它仍然无法远程连接。

配置Windows防火墙 (Configuring Windows Firewall )

From the Control Panel choose Windows Firewall and click the Advanced settings or just type wf.msc in Search program and files from the Start menu:

在“ 控制面板”中,选择“ Windows防火墙” ,然后单击“ 高级”设置,或仅在“ 开始”菜单的“ 搜索程序和文件”中键入wf.msc

  • Inbound Rules: You can allow or block traffic attempts to access the computer that matches certain criteria in the rule. By default inbound traffic is blocked, to allow traffic to access computer, you need to create inbound rule. 入站规则:您可以允许或阻止流量尝试访问符合规则中某些条件的计算机。 默认情况下,入站流量被阻止,要允许流量访问计算机,您需要创建入站规则。
  • Outbound Rules: You can allow or block traffic originating from specifying computer creating rules. By default outbound traffic is allowed, so you need to create the rule that block outbound traffic. 出站规则:您可以允许或阻止源自指定计算机创建规则的流量。 默认情况下,允许出站流量,因此您需要创建阻止出站流量的规则。

In the Windows Firewall with Advanced Security, click the Inbound Rules from the left pane, right click Inbound Rules and select the New Rule or from the Actions pane click the New Rule:

Windows高级安全防火墙 ,从左侧窗格中单击入站规则 ,右键单击入站规则 ,选择新规则或从操作窗格单击新建规则:

On which you will click, it’s up to you. In both case the New Inbound Rule Wizard will appear. Under the Rule Type choose Port and click the Next button:

您将在其上单击,这取决于您。 在两种情况下,都会出现“ 新建入站规则向导” 。 在规则类型下,选择端口 ,然后单击下一步按钮:

From this link you can more informed of all rule types which are shown in the image above.

通过此链接,您可以更了解上图中显示的所有规则类型。

In the Protocols and Ports there are a several options that you can choose, depending on which type of protocols you select.

协议和端口中,可以选择几个选项,具体取决于选择的协议类型。

If you are wondering what is the difference between the TCP and UDP protocols you can find from this link.

如果您想知道TCP和UDP协议之间有什么区别,可以从此链接中找到。

As we mentioned at the beginning of the article TCP is used for the default instance and named instance if is the only instance installed on the machine and default port is 1433.

正如我们在文章开头提到的,TCP是用于默认实例的,如果是机器上安装的唯一实例且默认端口为1433,则使用命名实例。

  • All local ports: Rule applies on all ports from the selected protocol. 所有本地端口 :规则适用于所选协议中的所有端口。
  • Specific local ports: In the text box you specify a port or set of ports to which the rule applies. 特定的本地端口 :在文本框中,您可以指定规则适用的端口或一组端口。

For this example, select the UDP protocol and in the Specific local ports enter port number 1434. To proceed with the settings SQL Browser services, click the Next button:

对于此示例,选择UDP协议,然后在“ 特定本地端口”中输入端口号1434。要继续设置SQL Browser服务,请单击“ 下一步”按钮:

  • Allow the connection: Includes all connections secure and insecure允许连接:包括所有安全连接和不安全连接.
  • Allow the connection if it is secure: Includes only connection if it is made through a secure channel. 如果安全,则允许连接 :仅通过安全通道建立的连接。
  • Block the connection: Blocks all connections secure and insecure. 阻止连接:阻止所有连接安全和不安全。

In the Action dialog choose Allow the connection and click the Next button:

在“ 操作”对话框中,选择“ 允许连接” ,然后单击“ 下一步”按钮:

  • Domain: The setting is applied only when a computer is connected to a domain. :仅当计算机连接到域时,才应用该设置。
  • Private: The setting is applied when a computer is connected to a network that is identified as a private network. 专用 :当计算机连接到标识为专用网络的网络时,将应用此设置。
  • Public: The setting is applied when a computer is connected to untrusted public network. 公共 :当计算机连接到不受信任的公共网络时,将应用此设置。

In the Profile dialog choose all three profiles and click the Next:

在“ 配置文件”对话框中,选择所有三个配置文件,然后单击“ 下一步”

On this step give the rule a name and click the Finish.

在此步骤中,为规则命名,然后单击“ 完成”

Note: When we give the name of the rule, please write some descriptive name that you can understand later, when you need to find them or edit in the Inbound Rules list.

注意 :当我们提供规则名称时,请写一些描述性名称,以后需要查找或在“入站规则”列表中进行编辑时,便可以理解。

Now create an allow rule for the database engine instance.

现在,为数据库引擎实例创建一个允许规则。

Go to the New Rule and from the Rule Type select the Custom rule:

转到“ 新规则”,然后从“ 规则类型”中选择“ 自定义”规则:

In the Program under the Services click the Customize button:

在“ 服务 下的“ 程序 ”中,单击“ 自定义”按钮:

From the Customize Service Settings under Apply to this service select database engine instance service and click the OK button:

应用于此服务 下的“ 定制服务设置” ,选择数据库引擎实例服务,然后单击“ 确定”按钮:

Then click the Next all the way to the Name dialog, give rule a name and click the Finish:

然后单击“ 下一步 ”到“ 名称”对话框,为规则指定名称,然后单击“ 完成”

Now when all rules are set up, you are ready to connect to remote SQL Server.

现在,当所有规则都设置好后,就可以连接到远程SQL Server了。

Start the SQL Server, in the dialog window for the Server name enters the name of the instance that you want to connect with. From the Authentication drop down box, select the SQL Server Authentication and for the field Login and the Password enter your credentials then click the Connect button.

启动SQL Server,在“ 服务器名称 ”对话框中输入要连接的实例的名称。 在“ 身份验证”下拉框中,选择“ SQL Server身份验证”,然后在“ 登录名”和“ 密码 ”字段中输入您的凭据,然后单击“ 连接”按钮。

看更多 (See more)

To boost SQL coding productivity, check out these free add-ins for SSMS and Visual Studio including T-SQL formatting, refactoring, auto-complete, text and data search, snippets and auto-replacements, sql code and object comparison, multi-db script comparison, object decryption and more.

为了提高SQL编码的生产力,请查看这些免费的SSMS和Visual Studio加载项,包括T-SQL格式,重构,自动完成,文本和数据搜索,摘要和自动替换,SQL代码和对象比较,多数据库脚本比较,对象解密等。

相关文章 ( Related posts )

  • How to install SQL Server Management Studio 2008如何安装SQL Server Management Studio 2008
  • Best practices after installing Microsoft SQL Server安装Microsoft SQL Server之后的最佳做法
  • SQL Server 2014 – Install a clustered instance – step-by-step (1/3) SQL Server 2014 –安装群集实例–分步(1/3)
  • How to run a local SQL Report from an Azure VM Database如何从Azure VM数据库运行本地SQL报表

翻译自: https://www.sqlshack.com/how-to-connect-to-a-remote-sql-server/

如何连接到远程SQL Server相关推荐

  1. 【远程连接 多个SQL SERVER数据库实例】

    远程连接 多个SQL SERVER数据库实例 前言 一.查看数据库实例动态端口 1. 打开SQL Server 配置管理器 2.打开TCP/IP,查看实例对应的端口号 3.远程连接对应的实例 二.设置 ...

  2. Visual Studio 2019连接自动的Sql Server开发版数据库(C#语言)

    Visual Studio 2019连接自动的Sql Server开发版数据库,C#语言 连接字符串: server=(LocalDB)\MSSQLLocalDB;database=master;in ...

  3. 连接不上sql server服务器的解决方案

    连接不上sql server服务器的解决方案 参考文章: (1)连接不上sql server服务器的解决方案 (2)https://www.cnblogs.com/linguosen/p/109966 ...

  4. Excel VBA通过ADO连接、操作SQL Server数据库的自定义函数

    网上大多数有关VBA连接.操作SQL Server数据库的教程,大多是把连接字串.SQL语句.执行过程全写在一个过程中了,当一个VBA项目需要做大量的查询.更新数据时,显然这种方法并不合适,以下代码是 ...

  5. java 连接多实例_Java如何连接多实例SQL Server?

    异常产生 Java连接SQL Server一般字符串:jdbc:sqlserver://127.0.0.1:1433;DatabaseName=数据库名; 大家应该知道:如果机器上安装的是SQLSer ...

  6. 关于通过外网连接内网SQL Server服务器的方法!

    近日,在论坛上看到sowant大侠发表的有关SQL Server远程连接的文章后,真的受益良多.一直以来困惑了已久的关于从外网如何连接到内网的SQL Server服务器上的方法,现已解决了,相信在论坛 ...

  7. vc访问远程mysql_vc实现对远程SQL Server数据库的访问

    1.远程数据库 设远程数据库的ip地址为192.168.0.1,其中testdb数据库中有student表,student表包含两列:name和age.name为char类型,长度为10:age为in ...

  8. bdm导入mysql_dblink insert 远程SQL Server数据库是报ORA-02063错误

    这两天在做一个项目的接口,需要将大量的数据从Oracle数据库上传到一个SQL SERVER 2005的数据库,我采用通过透明网关的方式解决. dblink建好后,检索SQL SERVER 2005上 ...

  9. Java JDBC连接oracle、SQL server、My Sql数据库的驱动

    JAVA创建以JDBC连接数据库的程序 ①加载JDBC驱动程序: 1.oracle---------JDBC try{//加载oracle的驱动类Class.forName("oracle. ...

最新文章

  1. python和javascript详细对比_python与javascript 引入模块的方法对比
  2. /etc/group 很好很强大
  3. python fine函数_python find()函数
  4. Linux系统下面crontab选择默认编译器
  5. elementUI响应式布局@media:基于断点的隐藏类
  6. SQL基础实例(学生课程系统)
  7. wpf 让图标显示在系统托盘
  8. OMP与MP算法流程与代码
  9. 算法入门—《啊哈算法》读书总结
  10. 60页5G+智慧农业大数据 2022
  11. VS Code C语言开发环境配置附图版保姆教程
  12. 百度指数使用小技巧(转)
  13. 远程桌面之客户端连接(MAC远程Windows桌面)
  14. java动画迷宫寻路_迷宫寻路算法
  15. twitter下载网络教程_糟糕的主意:喜p Twitter广告网络
  16. 对话MOV | DeFi2020——如何从开放应用走向开放生态?
  17. 那些你很冒险的梦 我们陪你一起去疯
  18. 【趣味程序】输入一行字符,统计其中有多少个单词,单词之间用空格隔开
  19. 离散正弦变换(DST)实现(cpu和cuda)
  20. 浅析SFX脚手架源码

热门文章

  1. np.array的shape的区别
  2. python字符串,列表常用操作
  3. hibernate入门实例
  4. linux中,一个目录的权限是777,普通用户为什么删除不了它呢?
  5. 读书笔记 - js高级程序设计 - 第四章 变量 作用域 和 内存问题
  6. BZOJ 1004: [HNOI2008]Cards [Polya 生成函数DP]
  7. 令人郁闷的DateTime.ToString()方法
  8. 【Vue】—事件处理
  9. JavaScript学习(六十二)—解析选项和序列化选项
  10. HTML之表格的基本知识