# Access database from usercontrol

**URL:** <https://forum.dotvvm.com/t/access-database-from-usercontrol/261>\
**Category:** Discussion in English\
**Created:** [September 13, 2024, 6:49am UTC](https://forum.dotvvm.com/t/access-database-from-usercontrol/261 "2024-09-13T06:49:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![daltinkurt](https://forum.dotvvm.com/user_avatar/forum.dotvvm.com/daltinkurt/32/11_2.png) [@daltinkurt](https://forum.dotvvm.com/u/daltinkurt)\
**Post date:** [September 13, 2024, 6:49am UTC](https://forum.dotvvm.com/t/access-database-from-usercontrol/261/1 "2024-09-13T06:49:46Z")

</div>

Hi,  
Is there a way to access the database from within the user control?

---

<div class="post-metadata">

**Author:** ![exyi](https://forum.dotvvm.com/user_avatar/forum.dotvvm.com/exyi/32/9_2.png) [@exyi](https://forum.dotvvm.com/u/exyi)\
**Post date:** [September 14, 2024, 11:09am UTC](https://forum.dotvvm.com/t/access-database-from-usercontrol/261/2 "2024-09-14T11:09:42Z")

</div>

I don’t think there is anything stopping you from doing that. You can request any dependencies from DI by adding them as a constructor parameter.

However, I’d advice against it and suggest placing the data fetching logic into the ViewModel of the control, if it a markup control. Nested view models can also inherit DotvvmViewModelBase and override the Init, Load, PreRender methods.
