为什么数据库连接导致加载数据很慢

发布于 2024-11-27 01:20:32 字数 387 浏览 0 评论 0原文

这是我的连接字符串:

<add name="ConnectionString" connectionString="Data Source=server;Initial Catalog=databaseName;Persist Security Info=True;User ID=username;Password=password" providerName="System.Data.SqlClient" />

当我从上面的 IP 地址运行时,我的 Web 应用程序运行良好,但在其他机器上运行速度很慢。

我的意思是它很慢但它有效。我认为连接字符串的类型存在问题,因为另一个使用 OleDb 的应用程序运行得很好。我该如何修复它?我不想更改我的应用程序代码。

This is my connection string :

<add name="ConnectionString" connectionString="Data Source=server;Initial Catalog=databaseName;Persist Security Info=True;User ID=username;Password=password" providerName="System.Data.SqlClient" />

my web application runs fine when I run it from above ip address but it is so slow in other machine.

I mean it is slow but it works. I think there is a problem in type of connection string because another application using OleDb works very well. how I can fix it? I don't want change my application code.

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

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

发布评论

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

评论(2

扎心 2024-12-04 01:20:32

该连接字符串没有什么根本性的错误。这留下了两种可能的情况:

  • 两台机器具有不同的网络拓扑 - 也许其中一台在地理上很远,通过慢速链路上的 VPN 隧道进行路由(仅出于说明目的而制作一个夸张的示例),
  • 也许一个应用程序是根据数据合理编写的访问,另一种不是

我想第二种是更可能的情况。如果您的应用程序代码没有在适当的位置进行过滤(即加载整个表以选择内存中的一行),那么是的:它会很差。

我不想更改我的应用程序代码。

如果我上面的猜测(第二个项目符号)是正确的,那么性能不佳完全是应用程序代码的错误,唯一的修复方法是更改​​应用程序代码; “想要”与此关系不大。如果您可以展示一些示例数据库访问代码,这显然会有所帮助,但请放心:ADO.NET 不会导致固有的缓慢。然而,写得不好的数据访问应用程序代码总是导致性能不佳。

如果问题实际上是网络拓扑,那么您必须为此进行设计;当数据库和应用程序相距较远时,为快速本地连接而设计的应用程序往往会表现不佳。唯一的解决办法是再次更改您的应用程序代码,使其不那么繁琐 - 并且希望减少延迟(大量小查询)和带宽(大查询)问题的影响。

There is nothing fundamentally wrong with that connection string. This leaves two likely scenarios:

  • the two machines have different network topology - maybe one is geographically distant, routing via a VPN tunnel on a slow link (making an absurdly exaggerated example for illustration only)
  • maybe the one application is sensibly written in terms of data access, and the other isn't

I imagine the second is the more likely scenario. If your application code doesn't filter at the appropriate places (i.e. loading an entire table to select a single row in memory), then yes: it will be poor.

I don't want change my application code.

If my guess above (the second bullet) is correct, then the poor performance is entirely the fault of application code, and the only fix would be to change the application code; "want" has very little to do with it. If you could show some of your example database access code that would obviously help, but rest assured: there is no inherent slowness caused by ADO.NET. However, poorly written data access application code will always result in bad performance.

If the issue is actually network topology, then you must design for that; applications designed for a fast local connection tend to perform badly when the DB and app are distant. The only fix there is, again, to change your application code to be less chatty - and hopefully less impacted by both latency (lots of small queries) and bandwidth (large queries) issues.

不乱于心 2024-12-04 01:20:32

您的 DNS 最近是否有更改?

尝试以下两项更改之一

  • 将数据源更改为 IP 地址:

    • 命令 shell:ping(服务器名称)——这将为您提供服务器的 IP
  • 将服务器名称更改为完全限定的,包括域名

    • 将“servername”设置为“servername.mydomain.com”,而不是“servername”

Were there changes made recently to your dns?

Try one of these two changes

  • Change the data source to an IP address:

    • command shell: ping (server name) -- this will give you the IP of the server
  • Change the server name to be fully qualified my including the domain name

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