介绍 (Introduction)

A while ago I discovered that you can conveniently connect to a local instance of SQL Server by typing one of the following names:

不久前,我发现您可以通过键入以下名称之一来方便地连接到SQL Server的本地实例:

  1. Dot (.), 点(。),
  2. (local), (本地),
  3. localhost, or 本地主机,或
  4. 127.0.0.1. 127.0.0.1。

Figure 1 illustrates how a successful SQL Server connection using the aforementioned names would look like in SQL Server Management Studio (SSMS):

图1说明了使用上述名称的成功SQL Server连接在SQL Server Management Studio(SSMS)中的样子:

Since the “discovery”, I had never seen any Microsoft-issued documentation that properly describes such a method of connecting to SQL Server, thus, I was personally referring to such practice as “connecting to SQL Server using shortcut keys”. However, it was only when I was researching for my article, SQL Server Lessons from a TFS Installation, that I came across the term “Convenience Names” as a formal reference by Microsoft (or at least from a Microsoft product) to “connecting to SQL Server using shortcut keys”. Figure 2 displays a TFS 2015 Readiness Check results in which the highlighted error relates to a prohibition for using SQL Server convenience names during a TFS Configuration.

自从“发现”以来,我从未见过任何Microsoft发行的文档来正确描述这种连接到SQL Server的方法,因此,我个人指的是“使用快捷键连接到SQL Server”这样的做法。 但是,只有当我在研究文章“ TFS安装中SQL Server经验教训”时 ,才碰到术语“便利名称”,作为Microsoft(或至少从Microsoft产品)的正式参考。 SQL Server使用快捷键”。 图2显示了TFS 2015准备情况检查结果,其中突出显示的错误与在TFS配置期间禁止使用SQL Server便捷名称有关。

This article sets out to provide an in depth analysis of SQL Server convenience names by focusing on its usage, its architecture, and providing guidance on when is most appropriate to make use of convenience names in SQL Server.

本文着重于通过重点研究SQL Server便捷名称的用法,其体系结构,并就何时最适合在SQL Server中使用便捷名称提供指导。

一个方便的类比 (A convenient analogy)

For me SQL Server convenience names are analogous to dialling a business telephone extension. For instance, as a South African based professional, when I have enquires relating to my payslip, instead of dialling the complete set of telephone numbers i.e. 011 345 9804, I can just dial the last 4 digits which is the extension to the Human Resources (HR) office of the organisation I work for. However, I can only get away with dialling the extension number only when I am in the premises of my employer. If I were to dial the last 4 digits of the aforementioned number from my house telephone, I will not reach the HR office as the number will become unrecognisable. Similarl to the telephone extension, if you attempt to connect to a remote SQL Server instance by typing a dot(.) – SQL Server will not recognise such a server address and you will run into the error message depicted in Figure 3.

对我来说,SQL Server便利名称类似于拨打商务电话分机 。 例如,作为一名南非专业人士,当我查询有关工资单的信息时,我无需拨打完整的电话号码即011 345 9804,而只需拨打最后4位数字,这是人力资源的扩展名( HR)我所在组织的办公室。 但是,只有在我的雇主所在地时,我才可以拨打分机号。 如果我要通过家庭电话拨打上述号码的后4位,由于号码将变得无法识别,因此我将无法联系人力资源办公室。 与电话分机类似,如果尝试通过键入点(。)连接到远程SQL Server实例,则SQL Server将无法识别该服务器地址,并且会遇到图3所示的错误消息。

SQL Server便捷名称的内部 (Internals of SQL Server convenience names)

1. SQL Server Network Configurations

1. SQL Server网络配置

A significant part of the discussion around the topic of SQL Server convenience names pertains to a discussion surrounding SQL Server Network Configurations. This is because part of making SQL Server convenience names work, involves a proper configuration of SQL Server TCP IP ports. Figure 4 provides a listing via netstat command of network connectivity and indicates that Process ID (PID) 1804 is listening on port 1433.

有关SQL Server方便性名称主题的讨论的很大一部分与围绕SQL Server网络配置的讨论有关。 这是因为使SQL Server便利名称起作用的部分原因在于SQL Server TCP IP端口的正确配置。 图4通过netstat命令提供了网络连接列表,并指出进程ID(PID)1804正在侦听端口1433。

When we go through the list of running services via Windows Task Manager, we can easily identify PID 1804 as belonging to the SQL Server default instance (MSSQLSERVER). Thus, one of the checks you can do to resolve the error depicted in Figure 3, is to run netstat commands to verify whether or not the instance you are trying to connect to has been configured for TCP connections.

当我们通过Windows任务管理器查看正在运行的服务的列表时,我们可以轻松地将PID 1804识别为属于SQL Server默认实例( MSSQLSERVER )。 因此,为解决图3中显示的错误,可以执行的一项检查是运行netstat命令,以验证您尝试连接的实例是否已配置为TCP连接。

2. The Connection Process

2.连接过程

Figure 6 depicts the sequence of events involved when connecting to SQL Server using convenience names. At the very beginning, a user uses a SQL Server enabled client tools such as SQL Server Management Studio (SSMS) or Visual Studio to establish a connection to a SQL Server instance. Within a client tool, a convenience name is provided as part of the connection string for a either a default instance or named instance. Usually, the default instance is linked to port 443 whilst ports for named instances are often dynamic.

图6描述了使用便捷名称连接到SQL Server时涉及的事件序列。 最初,用户使用启用了SQL Server的客户端工具(例如SQL Server Management Studio(SSMS)或Visual Studio)建立与SQL Server实例的连接。 在客户端工具内,提供便利名称作为默认实例或命名实例的连接字符串的一部分。 通常,默认实例链接到端口443,而命名实例的端口通常是动态的。

In order for us to illustrate the activities depicted in Figure 6, I have setup an Oracle Virtual Box VM named WIN-7. The VM has Windows 7 and SQL Server 2012 installed. SQL Server 2012 has two named instances, namely, WIN7-PC\SIFISOTEST123 and WIN7-PC\SIFISOTESTINSTAN. Figure 7 and 8 shows the TCP IP All properties for the two named instances. You can already see that although the default instance is not installed – port 1433 – is not readily assigned to any of the two instances, instead dynamic port numbers are allocated.

为了说明图6中的活动,我设置了一个名为WIN-7的Oracle Virtual Box VM。 VM已安装Windows 7和SQL Server 2012。 SQL Server 2012具有两个命名实例,分别是WIN7-PC \ SIFISOTEST123WIN7-PC \ SIFISOTESTINSTAN图78显示了两个命名实例的TCP IP All属性。 您已经可以看到,尽管没有安装默认实例-端口1433-并没有轻易分配给这两个实例中的任何一个,但是分配了动态端口号。

It is no surprise, therefore, that when we connect using a dot(.) a failure message is returned as no instance is linked to port 1433.

因此,当我们使用dot(。)连接时,由于没有实例链接到端口1433,因此返回失败消息也就不足为奇了。

Another way to confirm this is that when we run netstat command, there is no PID listening on port 1433, instead only the ports associated with named instances are configured.

确认这一点的另一种方法是,当我们运行netstat命令时,端口1433上没有PID侦听,而是仅配置了与命名实例关联的端口。

2.1. Connect to Default Instance Using SQL Server Convenience Names

2.1。 使用SQL Server便捷名称连接到默认实例

I later added a default instance to my VM and the default TCP IP all property is correctly configured to listen on port 1433 as shown in Figure 11.

后来我向我的VM添加了一个默认实例,并且默认的TCP IP all属性已正确配置为侦听端口1433, 如图11所示。

Now, if we try connecting using the dot(.) again, we successfully establish connection as shown in Figure 12.

现在,如果再次尝试使用dot(。)进行连接,我们将成功建立连接, 如图12所示。

2.2. Connect to Named Instance Using SQL Server Convenience Names

2.2。 使用SQL Server便捷名称连接到命名实例

So what if you don’t have a default instance and you want to connect to named instances using convenience names? The simplest way is to remove the named instance’s dynamic TCP port and set its TCP port property to 1433. In order for the changes to be effective, you will be required to restart the SQL Server the windows service linked to the named instance. Figure 13 indicates the updated TCP settings of instance SIFISOTEST123.

那么,如果您没有默认实例,并且想使用便捷名称连接到命名实例怎么办? 最简单的方法是删除命名实例的动态TCP端口,并将其TCP端口属性设置为1433。为了使更改生效,将需要重新启动链接到命名实例的Windows Server SQL Server。 图13表示实例SIFISOTEST123的更新的TCP设置。

As it can be seen in Figure 14 – we are now able to connect using the dot(.) and we can confirm this because an application event has been logged against instance WIN7-PC\SIFISOTEST123 (such an event is only logged upon successful connection).

如图14所示 –我们现在可以使用dot(。)进行连接,并且可以确认这一点,因为已针对实例WIN7-PC \ SIFISOTEST123记录了一个应用程序事件(这样的事件仅在成功连接后才记录)。

结论 (Conclusion)

In this article we have covered the internals and workings of SQL Server Convenience Names. Connecting to SQL Server using convenience names is an efficient and quick way to establish a connection to a SQL Server instance. It usually connects easily against a default instance – if configured but alterations can be done on the TCP IP All property to connect conveniently against named instances too. However, similarly to the business telephone extension, there are limitations to the usage of convenience names such as not being able to use them whilst connecting to a remote SQL Server.

在本文中,我们介绍了SQL Server便利名称的内部和工作原理。 使用便捷名称连接到SQL Server是建立与SQL Server实例的连接的高效快捷方式。 它通常可以轻松地与默认实例连接-如果已配置,但是可以在TCP IP All属性上进行更改,从而也可以方便地与命名实例连接。 但是,类似于商务电话分机,便利名称的使用受到限制,例如在连接到远程SQL Server时无法使用它们。

看更多 (See more)

Consider these free tools for SQL Server that improve database developer productivity.

考虑使用这些免费SQL Server工具来提高数据库开发人员的生产力。

参考资料 ( References )

  • Named Instance命名实例
  • SQL Server Network ConfigurationSQL Server网络配置
  • Network Statistics Commands网络统计命令

翻译自: https://www.sqlshack.com/sql-server-convenience-names/

SQL Server便利名称相关推荐

  1. SQL Server服务器名称填写IP不能访问问题解决

    SQL Server服务器名称填写IP不能访问问题解决 参考文章: (1)SQL Server服务器名称填写IP不能访问问题解决 (2)https://www.cnblogs.com/mwduoduo ...

  2. SQL Server 变量名称的Collcation跟Instance还是跟当前DB?

    使用SQL Server变量的时候碰到变量名称大小写的问题: 当前数据库是大小写不敏感的,但是声明变量之后发现变量名称是大小写敏感的.一直认为SQL Server的变量名称的Collcation是跟当 ...

  3. 局域网内无法使用UDL文件获取SQL Server服务器名称

    问题: 局域网内无法使用UDL文件获取SQL Server服务器名称 环境: 1.本地windows10操作系统笔记本一台 2.本地计算机开的windows xp虚拟机一台 描述: 1本地计算机安装了 ...

  4. SQL Server服务器名称与默认实例名不一致的修复方法

    SQL Server服务器名称与默认实例名不一致的修复方法 分类: 个人累积 SQl SERVER 数据库复制2011-08-10 09:49 10157人阅读 评论(0) 收藏 举报 sql ser ...

  5. 【转】SQL Server服务器名称与默认实例名不一致的修复方法

    服务器级的urn筛选器无效:筛选器必须为空,或服务器属性必须等于实际的服务器名称 这个问题是出在本地连接还是远程连接上,这个问题可能是由于修改过服务器名称导致的.你可以尝试在本地的服务器和SQL Se ...

  6. SQL Server服务器名称

    SQL Server的服务器名格式是 主机名\实例名 此主机名是WIN10-20180501C (计算机名), 实例名是SQLEXPRESS (2008版默认是这个) 本地:主机名可以使用localh ...

  7. sql server服务器位置,SQL语句实现查询SQL Server服务器名称和IP地址

    获取服务器名称: SELECT SERVERPROPERTY('MachineName') select @@SERVERNAME select HOST_NAME() 获取IP地址可以使用xp_cm ...

  8. SQL语句实现查询SQL Server服务器名称和IP地址_MsSql

    转载:https://edu.aliyun.com/a/12773 获取服务器名称: SELECT SERVERPROPERTY('MachineName') select @@SERVERNAME ...

  9. SQL SERVER 服务器名称的更改

    1.当前数据库的服务器名 :   select @@ServerName 2.查看当前的所有服务器名:    select * From Sys.SysServers 3.删除服务器名:    sp_ ...

最新文章

  1. 股市币市:数据分析与交易所最新公告(20190301)
  2. 学习jQuery的on事件
  3. python27安装教程-Python2和Python3安装教程
  4. Java代码风格:最终决定
  5. [NOI2019]回家路线
  6. Caffe2 的基本数据结构(Basics of Caffe2 - Workspaces, Operators, and Nets)[4]
  7. Django+Jquery+Ajax+验证码登录案例
  8. C# TCP 相关类与方法
  9. .Net给图片添加水印效果
  10. oracle 每分钟执行,CSS_ORACLE JOB INTERVAL参数设置, 1:每分钟执行nb - phpStudy
  11. 一个按照行来截取显示文章摘要的函数
  12. Onvif协议:门外汉理解ONVIF协议
  13. uni-app开发语音提示推送功能
  14. 奖金高达200万!武汉市便利店行业发展专项资金支持条件、材料及流程
  15. thread-specific stroage模式 一个线程一个储物柜
  16. ui设计需要做android和苹果版本,安卓和IOS系统对于UI设计来说一样吗
  17. poj2528 贴海报
  18. 播放器初始化配置重点
  19. 生成xslx文件,写入并读取
  20. phpmail通过qq发邮箱失败_PHP中利用PHPMailer配合QQ邮箱实现发邮件

热门文章

  1. Android界面性能优化最全总结、原理剖析
  2. springcloud配置动态更新
  3. MySQL-数据操作-增删改查
  4. Scrapy开发指南
  5. Intellij Idea 15 下新建 Hibernate 项目以及如何添加配置
  6. 整个技术架构结构设计
  7. 简单的企业网站后台的实现之流程
  8. leetcode[94]Binary Tree Inorder Traversal
  9. 微软发布Sample Browser for Windows 8版:5000示例代码,触手可及
  10. 关于bash中if语法结构的广泛误解(转)