# Working with Database: DataSourceManager getDataSources return unexpected empty list

**URL:** <https://platform.jetbrains.com/t/working-with-database-datasourcemanager-getdatasources-return-unexpected-empty-list/870>\
**Category:** IntelliJ Platform\
**Created:** [March 12, 2025, 4:36am UTC](https://platform.jetbrains.com/t/working-with-database-datasourcemanager-getdatasources-return-unexpected-empty-list/870 "2025-03-12T04:36:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhuohuang.yu](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/zhuohuang.yu/32/624_2.png) [@zhuohuang.yu](https://platform.jetbrains.com/u/zhuohuang.yu)\
**Post date:** [March 12, 2025, 4:36am UTC](https://platform.jetbrains.com/t/working-with-database-datasourcemanager-getdatasources-return-unexpected-empty-list/870/1 "2025-03-12T04:36:05Z")

</div>

I’m trying to list all datasource using the follow code

```auto
import com.intellij.database.psi.DataSourceManager;
import com.intellij.openapi.project.Project;
        ...
        List<DataSourceManager<?>> managers = DataSourceManager.getManagers(project);
        for (DataSourceManager<?> manager : managers) {
            List<?> dataSources = manager.getDataSources();
            ...
        }

```

And I do have a localhost database added via view-\>tool window-\>database.

Debuging the code show that there are two managers:

- LocalDataSourceManager
- SqlDataSourceManager

Both containing no datasource. So what is wrong with the above code?

---

<div class="post-metadata">

**Author:** ![Leonid.Bushuev](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/leonid.bushuev/32/786_2.png) [@Leonid.Bushuev](https://platform.jetbrains.com/u/Leonid.Bushuev)\
**Post date:** [March 13, 2025, 10:07am UTC](https://platform.jetbrains.com/t/working-with-database-datasourcemanager-getdatasources-return-unexpected-empty-list/870/3 "2025-03-13T10:07:42Z")

</div>

Hello!  
The code looks OK, it should work. What could I check:

1. ensure that this data source appears in the Database Explorer tree,
2. you’re getting the right project reference,
3. this code should be called not just after creating the data source, internal messages must be already completed and processed.

If it all doesn’t help, you can attach whole you code and I’ll try to help you.

---

<div class="post-metadata">

**Author:** ![zhuohuang.yu](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/zhuohuang.yu/32/624_2.png) [@zhuohuang.yu](https://platform.jetbrains.com/u/zhuohuang.yu)\
**Post date:** [March 13, 2025, 11:33am UTC](https://platform.jetbrains.com/t/working-with-database-datasourcemanager-getdatasources-return-unexpected-empty-list/870/4 "2025-03-13T11:33:02Z")

</div>

Thank you for the suggest.

> > you’re getting the right project reference,

This is the problem. I am running that code in an application configurable and so I’m not getting the right project reference. When I change it to a project configurable, it works.

---

<div class="post-metadata">

**Author:** ![Leonid.Bushuev](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/leonid.bushuev/32/786_2.png) [@Leonid.Bushuev](https://platform.jetbrains.com/u/Leonid.Bushuev)\
**Post date:** [March 13, 2025, 12:40pm UTC](https://platform.jetbrains.com/t/working-with-database-datasourcemanager-getdatasources-return-unexpected-empty-list/870/5 "2025-03-13T12:40:19Z")

</div>

I’m glad to hear you succeeded with it!
