简体   繁体   中英

What is the efficient way to store multiple values in Sql Server Session database?

I have 10 - 12 variables on my aspx page which needs to be stored in SQL server Session database(load balancer environment).

What is the the efficient way of storing and retrieving them

  1. group every thing in a class and and store in session ( i am thinking this will reduce the number of database calls)

  2. Storing each variable in session ( I am thinking this will make database calls for every session object i stored)

Can any of you please suggest me the efficient way to do it?

It probably doesn't matter in terms of performance, so use whatever produces the cleanest code.

Each separate session item does not require a separate database call. The entire session is loaded from the db at the start of the request; the entire** session is then written back to the db at the end of the request (assuming that the request isn't using a read-only session).

There will be minor performance differences due to how native types are serialised compared to custom objects (size of the serialised data and/or CPU cost to serialise). These differences will usually be minor compared to the cost of the round-trips to the database.


** I must admit that I can't actually remember whether the entire session is written back to the db or only those items that have been added/modified during the current request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM