会议上的问题 [英] question on session

查看:80
本文介绍了会议上的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在会话中存储datareader/dataset吗?如果可以,那么更好,更快

can we store datareader/dataset in session.if yes which is better and faster

推荐答案

您可以在会话中存储这两个数据.在会话中存储DataReader毫无用处,恕我直言,因为它只提供一次访问.

您也可以存储DataSet,但前提是它不能太大.
You can store both in session. Storing DataReader in session is of no use, IMHO, since it gives only one time access.

You can store DataSet too but only if it is not too huge.


请勿在会话中存储DataReader. DataReader仅用于查询响应的正向迭代.因此,它必须是开放的.如果在会话中存储打开的DataReader,则连接(作为稀缺资源)将由DataReader保留.

将DataReader读入某种数据结构(例如DataReader),然后再存储在会话中.

现在出现下一个问题,如果您要存储的数据很大,则每个用户会话都可以存储此数据.

我建议改用Cache.您可以设置超时时间,如果用户对于相同的查询参数都需要相同的结果,可以在用户之间共享数据.
Do not store a DataReader in session. A DataReader is only of use for forward only iteration of a query response. As such, it must be open. If you store an open DataReader in session, the connection ( as scarce resource) will be held by the DataReader.

Read the DataReader into some data structure, such as a DataReader, before storing in session.

Now comes the next problem, if the data you are storing is large, each user session could store this data.

I would recomment using the Cache instead. You can set a timeout on how long it is stored and you could share the data between users if they all need the same result for the same query parameters.


假设您的网站将被以下用户使用如果超过3人,那么胜任的开发人员所采取的方法将是尽可能不使用该会话.在查询字符串上放置一个ID,并使用该ID从您的数据源读取数据.这意味着您可以为页面添加书签,它们将计算出如何使用添加了书签的数据来加载自身.如果必须使用会话,请使用它存储ID,并仍从数据源读取它.
Assuming your site will be used by more than 3 people, the approach taken by competent developers would be to never use the session if at all possible. Put an id on the query string and use that to read the data from your data source. This means you can bookmark pages and they will work out how to load themselves with the data that was bookmarked. If you MUST use the session, use it to store an id, and still read it from the data source.


这篇关于会议上的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆