Last post Dec 22, 2011 08:26 PM by Decker Dong - MSFT
Dec 21, 2011 12:12 AM|Saavik|LINK
I was told a long time ago, that if my application does a lot of database access, there may be a performance gain by saving an SqlDataSource object to Session variable and reusing it next time it is needed.
Is this true? Are there ANY advantages to doing this vs. creating a fresh SqlDataSource (SqlDataSource sds = new SqlDataSource) each time it is needed?
I may be experiencing a problem with a saved SqlDataSource, so help is most appreciated.
Dec 21, 2011 12:30 AM|gaikwad_anil1987|LINK
if you save Data to session Then you won't need to access the data again i.e. you don.t need to make another call to database ,
Instead you can call get data from Session
Dec 21, 2011 12:36 AM|Saavik|LINK
Thank you for your quick reply.
I understand saving the data is definitely faster than database access.
I am asking about the advantage (if any) to saving an empty SqlDataSource object to session vs. creating a new one each time database access is needed.
Dec 21, 2011 01:03 AM|umairaslam22|LINK
Basically you can judge it yourself besides technology let me clarify you
For every instance of creating any new object (sql data source or any) you are making you page to go through the cycle of data binding every time , as server controls send request on every post back and even page redirects
The only advantage you get is that datasource is already filled and you dont have to creat its new instance , and it show you data quickly .
But a completely new datasource will go through data binding again , again callback to db hence slow down the performance.
So getting data from session is faster as compared to database.
And i recommend you to use DataTable instead of sqldatasource for storing it in session , as dataTable has various flavours of data base operations available (filtering , sorting etc)
Dec 22, 2011 08:26 PM|Decker Dong - MSFT|LINK
If possible，you can also use Cache to deal with the problem to make a good and fast performace……I guess this artible will help you at some point：http://msdn.microsoft.com/en-au/library/z56y8ksb(v=vs.80).aspx