SQL Server 实例的连接字符串

发布于 2024-10-16 20:24:29 字数 981 浏览 8 评论 0原文

我有 SQL Server 2000,它还有另外 2 个 sql 实例。主服务器没有问题,下面我讨论这两个实例,

他们共享,

  1. 同一台机器
  2. 相同的IP
  3. 相同的实例名称
  4. 相同端口

我也想知道它是如何做到的。

使用查询分析器一旦连接到,

MyServer\Invent (it connects to first instance)
MyServer\Invent,1433 (it connects to second instance)

(是的,它发生了。我对此百分百确定,因为我里面有单独的数据库)

现在出现问题,

使用 C# SqlConnection,我无法连接到第一个,但可以连接到第二。

1. Data Source=MyServer\Invent;Persist Security Info=True;Initial Catalog=TEST;uid=admin;pwd=123
2. Data Source=MyServer\Invent,1433;Persist Security Info=True;Initial Catalog=TEST;uid=admin;pwd=123

一旦我使用第一个连接字符串,它会挂起一段时间并收到以下错误消息...

在建立与 SQL Server 的连接时发生网络相关或特定于实例的错误。找不到服务器或无法访问服务器验证实例名称是否正确,并且 SQL Server 是否配置为允许远程连接(提供程序:SQL 网络接口,错误:26 - 指定服务器/实例错误)

在网上搜索,很多人说。安装这样的是可能的。并且一个连接应该使用命名管道(tcp/445)

知道如何解决这个问题吗? 任何可能的连接字符串格式? 无论如何为命名管道创建连接字符串?

I have SQL server 2000, and it have 2 other sql instances as well. Main sever has no issues, hereafter I am talking about those two instances,

They share,

  1. Same machine
  2. Same IP
  3. Same Instance Name
  4. Same Port

I too wonder how it has done.

Using query analyzer Once connect to,

MyServer\Invent (it connects to first instance)
MyServer\Invent,1433 (it connects to second instance)

(Yeah, it happens. I am 100% sure on that because I have separate DBs inside them)

Now it comes to problem,

With C# SqlConnection, I am unable to connect to first one, but can connect to second.

1. Data Source=MyServer\Invent;Persist Security Info=True;Initial Catalog=TEST;uid=admin;pwd=123
2. Data Source=MyServer\Invent,1433;Persist Security Info=True;Initial Catalog=TEST;uid=admin;pwd=123

Once I used 1st Connection String it hangs for a while and gets following error message...

"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"

Searched on net for this, many says installing such is possible. And one connection should use named pipes (tcp/445)

Any idea how to resolve this ?
Any possible Connection String format ?
Anyway of making Connection String for named pipes ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别再吹冷风 2024-10-23 20:24:30

我认为您的问题是一台服务器使用不同的端口。因此它使用 TCP,但端口不同,您需要弄清楚它使用的端口是什么,然后将该端口添加到您的连接字符串中,就像您对其他实例 (1433) 所做的那样。

你是 SQL Server 配置管理器。
导航到 SQL Server 网络配置节点并将其展开。
在子节点中找到实例
现在在右侧您将看到协议(共享内存、命名管道、TCP 等)
双击 TCP。
在弹出的对话框中,切换到“IP 地址”选项卡。
一直向下滚动到“IP All”部分,

TCP 端口有何含义?
在此处输入图像描述

I think your issue is that the one server is using a different port. So it's using TCP but a different port and you'll need to figure out what port is it using and then add that port to your connection string like you're doing with the other instance (1433).

you SQL Server configuration manager.
Navigate to the SQL Server Network Configuration Node and expand it.
Locate the instance in the children nodes
Now on the right hand side you'll see Protocols (Shared Memory, Named Pipes, TCP etc.)
Double Click on TCP.
In the dialog that pops up, switch to the IP Address tab.
Scroll all the way down to the "IP All" section

What does it say for TCP Port?
enter image description here

暮年 2024-10-23 20:24:30

我认为也许您的第一个实例实际上并未侦听 1433,尽管这通常是默认设置。

我相信可以使用 SQL Server 配置实用程序更改默认端口。检查默认端口是什么,假设它不是 1433,请尝试在第一个连接字符串中指定它。

以下是有关如何检查您的实例正在侦听哪个端口的一些信息

编辑:好的,第一个实例正在监听命名管道。也许 server=np:MyServer\Invent; 会起作用,按照此页面。

I think maybe your first instance is not actually listening on 1433, even though that is usually the default.

I believe it's possible to change the default port with the SQL Server Configuration utility. Check what the default port is, and assuming it's not 1433, try specifying it in the first connection string.

Here's some info about how to check which port your instance is listening on.

Edit: Ok, the first instance is listening on a named pipe. Maybe server=np:MyServer\Invent; will work, as per this page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文