从数据库收集数据的最快方法?

发布于 2024-12-14 22:59:48 字数 233 浏览 0 评论 0原文

使用 C# 工作。在我的应用程序中,多次需要选择\从数据库收集数据。对于此任务,我执行以下步骤,

1)Write SP 
2)Execute the Sp 
3)Fill result to Generic collection(ORM)
4)By the collection Bind the control

我想知道是否有任何机制或技术\高级技术可帮助从数据库收集数据。提前致谢

Work on C#.In my application several time need to select\collect datafrom DB.Fro this task I do the bellow step

1)Write SP 
2)Execute the Sp 
3)Fill result to Generic collection(ORM)
4)By the collection Bind the control

I want to know is there any mechanism or technique \Advanced technique available help to collect data from database.Thanks in advance

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

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

发布评论

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

评论(2

樱花细雨 2024-12-21 22:59:48

当我一次又一次地快速访问数据库时,它的性能就会成为瓶颈。该怎么办?

听起来您应该缓存一些结果。在高负载应用程序中,即使缓存几秒钟也会对性能产生很大影响。有无数的缓存解决方案;如果这是一个 Web 应用程序,内置的 http 上下文 .Cache 应该没问题(.NET 4.0 添加了 MemoryCache 以便在非 Web 应用程序中更方便地执行相同操作)。

重新加载数据;你提到了 ORM - 根据我们的经验,我们发现大多数 ORM 确实是“热”代码路径的瓶颈 - 我将在几个小时内讨论这个主题。因为我们面临这个问题,所以我们故意编写了一个简单但确实非常快速的micro-ORMdapper-dot-net。它不像一些完整的 ORM 那样功能丰富,但如果您想快速加载数据以进行显示,那么它是理想的选择。


当然,另一件事是查看您的查询并提高性能。特别查看逻辑 IO 读取以及它们来自何处。额外的索引或一点点非规范化很可能会对您的查询性能产生很大的影响。

When i again and again rapidly hit the db.then it's performance become bottleneck .What to do?

It sounds like you should be caching some results. In a high load application, caching even for a few seconds can have a big impact on performance. There are a myriad of cache solutions out there; if this is a web app, the inbuilt http-context .Cache should be fine (.NET 4.0 adds MemoryCache to do the same more conveniently in non-web applications).

Re loading the data; you mention ORM - in our experience here, we find most ORMs indeed are a bottleneck for "hot" code paths - a subject I'm talking on in a few hours as it happens. Because we faced this problem, we wrote an intentionally simple but really really fast micro-ORM, dapper-dot-net. It isn't as feature rich as some full ORMs, but if you are trying to load data quick for display, it is ideal.


The other thing, of course, is to look at your query and improve the performance. Look in particular at the logical IO reads, and where they are coming from. It could well be that an extra index or a little denormalization could make a really big difference to your query performance.

堇年纸鸢 2024-12-21 22:59:48

是的,但唯一的例外是使用 DataReader 或 DataTable。

对于前。 datareader 对于检索大集合中的行的有限视图很有用。

然而,如果要在完整的数据集合上应用函数,数据表很重要。

另外,还有不同的方法,例如连接池、本地视图、索引,当获取的数据多于可用的服务器资源时,这些方法将最为重要。

Ye, but the only exception is to use a DataReader or a DataTable.

For ex. datareader is usefull for limited view of rows from a large collection being retrieved.

However Datatable is important, if to apply functions on a complete collection of Data.

Plus there are different methods like connection pooling, localviews, indexes that will matter most when Data fetched is more than available Server resources.

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