开发者

one database connection object in asp.net mvc model

开发者 https://www.devze.com 2022-12-17 08:17 出处:网络
I have asp.net mvc 开发者_开发百科site, my action generate the page, using master page. on master page included widgets by RenderAction helper. How can i use one database connection in page controller

I have asp.net mvc 开发者_开发百科site, my action generate the page, using master page. on master page included widgets by RenderAction helper. How can i use one database connection in page controller and in widget controller?


Generally you shouldn't need to worry about this, because connection pooling will take care of it automatically. Just make sure to close your connections when you're done with them (best is to use the using {} block in your code, which will automatically close and dispose your connection).

If you really need to work off the same connection object for some reason, why not have all your controllers inherit from a base controller that exposes your connection object as a property?

0

精彩评论

暂无评论...
验证码 换一张
取 消