Working with Database: DataSourceManager getDataSources return unexpected empty list

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

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?

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.

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.

I’m glad to hear you succeeded with it!