C# 到 SQL Server 群集的连接字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/751634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
connection string to a SQL Server cluster
提问by George2
Could anyone point me or tell me how to write connection string to a SQL Server cluster instance?
谁能指出我或告诉我如何将连接字符串写入 SQL Server 群集实例?
I want to establish trusted connection to a database (initial catalog) of the specific instance of a SQL Server cluster. I find for quite some time but can not find official answer from Google.
我想建立到 SQL Server 群集特定实例的数据库(初始目录)的可信连接。我找到了很长一段时间,但无法从谷歌找到官方答案。
I am asking for the connection string for C# ADO.Net code.
我要求 C# ADO.Net 代码的连接字符串。
I know how to write connection string to a normal one-machine non-cluster SQL Server instance.
我知道如何将连接字符串写入普通的单机非集群 SQL Server 实例。
回答by gbn
The server name is the virtual server name.
服务器名称是虚拟服务器名称。
Example:
例子:
- You have Physical
pserver1
,pserver2
- These together make cluster
cserver
-This hosts virtual serversvserv1
(and perhaps, see below)vserv2
- 你有体力
pserver1
,pserver2
- 这些一起构成集群
cserver
- 这托管虚拟服务器vserv1
(也许,见下文)vserv2
So, it's vserv1\instancename
or vserv1
. you don't use physical server names
所以,它是vserv1\instancename
或vserv1
。您不使用物理服务器名称
Edit, based on number of possible names for virtual servers:
根据虚拟服务器的可能名称数量进行编辑:
The cluster may be active/passive /A/P) or active/active (A/A)
集群可能是主动/被动/A/P) 或主动/主动 (A/A)
- In A/P, only one virtual server is hosted and the standby node is not actively used.
- In A/A, there are 2 virtual servers and normally each node hosts one. Each node is standby for the other.
- 在 A/P 中,仅托管一台虚拟服务器,并且不主动使用备用节点。
- 在 A/A 中,有 2 个虚拟服务器,通常每个节点托管一个。每个节点都是另一个节点的备用节点。
回答by M.Turrini
The connection string is written in the usual way; but in clustering you have 3 (or more) addresses: one for each node which constitues the cluster and one for the cluster. E.g.: we have two node with addresses 192.168.0.10 and 192.168.0.20: if you write down one of this numbers as the DataSource in the connection string, you'll gain access to that physical instance. But if you want to access the cluster (virtual) Sql Server instance, you'll have to use the cluster's address (e.g.: 192.168.0.230) as the DataSource. Of course, you can also use the machines' names instead of the IP addresses, provided you are in the same domain as the cluster.
连接字符串以通常的方式编写;但是在集群中,您有 3 个(或更多)地址:一个用于构成集群的每个节点,一个用于集群。例如:我们有两个节点,地址分别为 192.168.0.10 和 192.168.0.20:如果您在连接字符串中记下这些数字之一作为数据源,您将获得对该物理实例的访问权限。但是如果要访问集群(虚拟)Sql Server 实例,则必须使用集群的地址(例如:192.168.0.230)作为数据源。当然,您也可以使用机器的名称而不是 IP 地址,前提是您与集群在同一个域中。
回答by Doug
This is not documented anywhere that I could find, but I had to use the name of the availability group listener on the cluster. For example:
这在我能找到的任何地方都没有记录,但我必须使用集群上的可用性组侦听器的名称。例如:
data-source=tcp:AG1-Listener
Literally, this is documented nowhere. I got lucky and found a connection string to a cluster on a blog somewhere and figured it out from there.
从字面上看,这是无处记录的。我很幸运,在某个地方的博客上找到了一个集群的连接字符串,并从那里找到了它。
回答by Roy Latham
I know this is an old thread but:
我知道这是一个旧线程,但是:
https://support.microsoft.com/en-us/kb/273673
https://support.microsoft.com/en-us/kb/273673
explains why a timeout should be specified on the connection. An extract is below.
解释了为什么应该在连接上指定超时。摘录如下。
If a SQL Server server is failed over by the cluster admin, TCP reset packets are not sent. If the SQL Server process is terminated by the operating system (by Kill.exe), the reset packets are sent.
如果群集管理员对 SQL Server 服务器进行故障转移,则不会发送 TCP 重置数据包。如果 SQL Server 进程被操作系统(通过 Kill.exe)终止,则发送重置数据包。
This may affect the client application if the application does not specify a query timeout parameter or a query timeout of zero (0).
如果应用程序未指定查询超时参数或查询超时为零 (0),这可能会影响客户端应用程序。
If the application does not have a query timeout value then open connections will be left in the ESTABLISHED state after a failover occurs. The fact that the open connections are not closed and that no further TCP packets are sent from those connections indicates that those connections are completely idle. Because the failover did not send any TCP reset packets to the client application, those open connections wait for the query results indefinitely (assuming an infinite query timeout), and potentially cause the connection to stop responding (hang).
如果应用程序没有查询超时值,则在发生故障转移后,打开的连接将处于 ESTABLISHED 状态。打开的连接没有关闭,并且没有进一步的 TCP 数据包从这些连接发送,这一事实表明这些连接完全空闲。因为故障转移没有向客户端应用程序发送任何 TCP 重置数据包,这些打开的连接无限期地等待查询结果(假设无限查询超时),并可能导致连接停止响应(挂起)。