为什么简单的sql连接会打开很多本地端口?
我有一个仅打开到远程主机的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有权查看远程数据库服务器中打开的数据库连接,请将其与托管应用程序的计算机中打开的 tcp/ip 连接进行比较。
如果数据库服务器上打开的连接数与相应的 tcp/ip 连接数匹配,则可以确定同时打开了多个连接,并进一步调试。
在 SQL Server 2008 中,执行
sp_who2
或打开活动监视器。您应该能够从结果中识别连接源。在应用程序主机中使用netstat -n
或其他网络监控工具。参见
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 usenetstat -n
or other network monitoring tool.See Also
我猜您还没有关闭 sqlconnection 并且它已连续打开,请尝试重新启动服务器并(也尝试重新启动计算机)。并在完成工作后使用此代码。它以前发生在我身上,这对我有用。
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 .