为什么数据库连接导致加载数据很慢
这是我的连接字符串:
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该连接字符串没有什么根本性的错误。这留下了两种可能的情况:
我想第二种是更可能的情况。如果您的应用程序代码没有在适当的位置进行过滤(即加载整个表以选择内存中的一行),那么是的:它会很差。
如果我上面的猜测(第二个项目符号)是正确的,那么性能不佳完全是应用程序代码的错误,唯一的修复方法是更改应用程序代码; “想要”与此关系不大。如果您可以展示一些示例数据库访问代码,这显然会有所帮助,但请放心:ADO.NET 不会导致固有的缓慢。然而,写得不好的数据访问应用程序代码将总是导致性能不佳。
如果问题实际上是网络拓扑,那么您必须为此进行设计;当数据库和应用程序相距较远时,为快速本地连接而设计的应用程序往往会表现不佳。唯一的解决办法是再次更改您的应用程序代码,使其不那么繁琐 - 并且希望减少延迟(大量小查询)和带宽(大查询)问题的影响。
There is nothing fundamentally wrong with that connection string. This leaves two likely scenarios:
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.
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.
您的 DNS 最近是否有更改?
尝试以下两项更改之一
将数据源更改为 IP 地址:
将服务器名称更改为完全限定的,包括域名
Were there changes made recently to your dns?
Try one of these two changes
Change the data source to an IP address:
Change the server name to be fully qualified my including the domain name