atoMerz
atoMerz

Reputation: 7672

Is SqlDataSource created for each client that connects to a server?

Assume I have a page with a data grid bound to a data source. If I have 2 different clients accessing this page, is the data source different for each of them, or do they use the same data source?

Upvotes: 1

Views: 156

Answers (2)

James Johnson
James Johnson

Reputation: 46047

The SqlDataSource control is an instance class, so it would be recreated on each request. You may want to look into connection pooling though, so you can reuse database connections.

I don't think it's possible to make the control static, and I don't think you need to make the control static. If you want to reuse the dataset for all users who visit the page, I would look into caching the DataSet, or storing it in application state. I believe you can do this with the SqlDataSource using a mixture of the OnSelecting and OnSelected events.

  • Cache the DataSet in the OnSelected event
  • In the OnSelecting event, check to see whether you have a cached DataSet, and cancel the the select if you do.

Upvotes: 1

kmcc049
kmcc049

Reputation: 2801

They are separate unless you have made the Dataset static, then it will be shared across all instances of the page. I'm not sure what problem you are trying to solve exactly? Is there no database behind the dataset? Or are you worried about the memory consumption?

Upvotes: 0

Related Questions