为什么简单的sql连接会打开很多本地端口?

发布于 2024-11-15 00:30:37 字数 255 浏览 1 评论 0原文

我有一个仅打开到远程主机的 SqlConnection 的应用程序。 我的代码是这样的:

SqlConnection sc = new SqlConnection();
sc.ConnectionString = sConnectionString;
sc.Open();

我在网络监控工具打开时运行应用程序。我注意到有 4 个本地端口打开,与远程主机的 1433 端口进行通信。我预计只有 1 个端口会打开。为什么会这样呢?

I have an application that simply opens an SqlConnection to a remote host.
My code is something like this:

SqlConnection sc = new SqlConnection();
sc.ConnectionString = sConnectionString;
sc.Open();

I ran the application while my network monitoring tool is open. I noticed that there were 4 local ports opened that communicates with the 1433 port of the remote host. I am expecting that only 1 port will open. Why is this so?

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

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

发布评论

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

评论(2

段念尘 2024-11-22 00:30:37

如果您有权查看远程数据库服务器中打开的数据库连接,请将其与托管应用程序的计算机中打开的 tcp/ip 连接进行比较。

如果数据库服务器上打开的连接数与相应的 tcp/ip 连接数匹配,则可以确定同时打开了多个连接,并进一步调试。

在 SQL Server 2008 中,执行 sp_who2 或打开活动监视器。您应该能够从结果中识别连接源。在应用程序主机中使用netstat -n或其他网络监控工具。

参见

与 SQL 2005 的连接过多

If you have permissions to see the open database connections in the remote database server, compare this to the tcp/ip connections open in the machine hosting the application.

If the number of connections open on the database server match with the corresponding tcp/ip connections, you can be sure that there are multiple simultaneous connections open, and debug this further.

In SQL Server 2008, execute sp_who2 or open the Activity Monitor. You should be able to identify the connection sources from the results. In the application host use netstat -n or other network monitoring tool.

See Also

Too many connections to SQL 2005

阳光下慵懒的猫 2024-11-22 00:30:37

我猜您还没有关闭 sqlconnection 并且它已连续打开,请尝试重新启动服务器并(也尝试重新启动计算机)。并在完成工作后使用此代码。它以前发生在我身上,这对我有用。

SqlConnection sc = new SqlConnection();
sc.ConnectionString = sConnectionString;
sc.Open();
// do you coding here 
// complete all the operations related to this connection 
//close the connection 
sc.Close();

I am guessing that you haven't closed your sqlconnection and it has been opened continuously , try restarting the server and (try restarting your computer as well) . And use this code after you do your work. It happened to me before and this worked for me .

SqlConnection sc = new SqlConnection();
sc.ConnectionString = sConnectionString;
sc.Open();
// do you coding here 
// complete all the operations related to this connection 
//close the connection 
sc.Close();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文