SonarQube server installation - Fail to connect to database

I developed the project using C #.net and plan to use the SonarQube for code quality and security. I am using to Install SonarQube using a docker-compose file in Windows Server 2019.

  • Docker Engine - v20.10.5
  • docker-compose version 1.29.0, build 07737305

I can’t able to install the server having an issue with connecting the database

2021.04.23 18:34:57 INFO web[o.sonar.db.Database] Create JDBC data source for jdbc:postgresql://db:5432/sonar
2021.04.23 18:35:08 ERROR web[o.s.s.p.Platform] Web server startup failed
java.lang.IllegalStateException: Fail to connect to database
at org.sonar.db.DefaultDatabase.start(DefaultDatabase.java:90)
at org.sonar.core.platform.StartableCloseableSafeLifecyleStrategy.start(StartableCloseableSafeLifecyleStrategy.java:40)
at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
at org.picocontainer.behaviors.Stored.start(Stored.java:110)
at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1016)
at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1009)
at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:135)
at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:90)
at org.sonar.server.platform.platformlevel.PlatformLevel1.start(PlatformLevel1.java:160)
at org.sonar.server.platform.Platform.start(Platform.java:211)
at org.sonar.server.platform.Platform.startLevel1Container(Platform.java:170)
at org.sonar.server.platform.Platform.init(Platform.java:86)
at org.sonar.server.platform.web.PlatformServletContextListener.contextInitialized(PlatformServletContextListener.java:43)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4705)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5171)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1412)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1402)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Can not connect to database. Please check connectivity and settings (see the properties prefixed by ‘sonar.jdbc.’).
at org.sonar.db.DefaultDatabase.checkConnection(DefaultDatabase.java:134)
at org.sonar.db.DefaultDatabase.start(DefaultDatabase.java:87)
… 24 common frames omitted

Kindly help me to up my SonarQube server.

Hello @Sakthivel and welcome to the community :wave:

can you post your compose file and tell us a little about your environment? Windows server 2019 and docker do have some quirks, so maybe the docker network is not created or the service lookup does not work.

Hello @Tobias_Trabelsi

Thanks for your response.


version: “2”

services:
sonarqube:
image: sonarqube:7.9-community
expose:
- 9000
ports:
- “0.0.0.0:9000:9000”
networks:
- sonarnet
environment:
- SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar
- SONARQUBE_JDBC_USERNAME=sonar
- SONARQUBE_JDBC_PASSWORD=sonar
volumes:
- sonarqube_conf:/opt/sonarqube/conf
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_bundled-plugins:/opt/sonarqube/lib/bundled-plugins

db:
image: postgres
networks:
- sonarnet
environment:
- POSTGRES_USER=sonar
- POSTGRES_PASSWORD=sonar
volumes:
- ./postgresql:/var/lib/postgresql
- ./postgresql_data:/var/lib/postgresql/data

networks:
sonarnet:

volumes:
sonarqube_conf:
sonarqube_data:
sonarqube_extensions:
sonarqube_bundled-plugins:
postgresql:
postgresql_data:


The given above it’s my docker compose file, File location placed in "C:\Users\Administrator\SonarQube-Jenkins\SonarQube\docker-compose.yml

Thanks,
Sakthivel S

is your database actually running? these look like fine system mounts and not the named volumes that you mention later on in this compose file?

try this compose file here:

version: "2"

services:
  sonarqube:
    image: sonarqube:7.9-community
    expose:
      - 9000
    ports:
      - "0.0.0.0:9000:9000"
    networks:
      - sonarnet
    environment:
      SONARQUBE_JDBC_URL: "jdbc:postgresql://db:5432/sonar"
      SONARQUBE_JDBC_USERNAME: "sonar"
      SONARQUBE_JDBC_PASSWORD: "sonar"
    volumes:
      - sonarqube_conf:/opt/sonarqube/conf
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions
  db:
    image: postgres
    networks:
      - sonarnet
    environment:
      POSTGRES_USER: "sonar"
      POSTGRES_PASSWORD: "sonar"
    volumes:
      - postgresql:/var/lib/postgresql
      - postgresql_data:/var/lib/postgresql/data

networks:
  sonarnet:

volumes:
  sonarqube_conf:
  sonarqube_data:
  sonarqube_extensions:
  postgresql:
  postgresql_data:

i also removed the volume for sonarqube_bundled-plugins as this is not needed and can lead to failures in the upgrade

Hello @Tobias_Trabelsi

Thanks to the above compose file works for me and I have installed the SonarQube server, but while I am trying to Creating a Jenkins server the below error message has been showned.

Kindly help me to resolve the issue.


C:\Users\Administrator\SonarQube-Jenkins\Jenkins>docker-compose up -d
WARNING: Some networks were defined but are not used by any service: test
Docker Compose is now in the Docker CLI, try docker compose up

Creating network “jenkins_default” with the default driver
Pulling jenkins (jenkins/jenkins:latest)…
latest: Pulling from jenkins/jenkins
bd8f6a7501cc: Pull complete
4af6ddab1982: Pull complete
bf5a83c5e318: Pull complete
8959d4c7ea38: Pull complete
5de31dce0eb9: Pull complete
d348df3ed5db: Pull complete
fbec506a4e55: Pull complete
6ff6a951a82b: Pull complete
1cbe4b38fcee: Pull complete
dd9a253fdadc: Pull complete
7875f11dbfdd: Pull complete
d8d5d36e41e5: Pull complete
779a3761eaaf: Pull complete
113c8d5c4607: Pull complete
90338f955944: Pull complete
2a345e8a8f3f: Pull complete
Digest: sha256:47800708ab85d0117918114f221aed05ec8486caf6fc1573e5b5b26f8c8429c4
Status: Downloaded newer image for jenkins/jenkins:latest
Creating jenkins_jenkins_1 … error

ERROR: for jenkins_jenkins_1 Cannot start service jenkins: Ports are not available: listen tcp 0.0.0.0:50000: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

ERROR: for jenkins Cannot start service jenkins: Ports are not available: listen tcp 0.0.0.0:50000: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
ERROR: Encountered errors while bringing up the project.


Thanks,
Sakthivel S

Hi @Sakthivel

glad that sonarqube is now up and running for you. general docker help is a little too much for this forum here, but from the log you posted i would start to have a look at this message here

eigher there is a permission problem with the user that starts the stack or the port specified is already in use.
Apart from that there is a dangling network in cour compose file

have a good day and good luck with your devops stack

Hi @Tobias_Trabelsi

Thanks for your help, Yes you are correct I changed my port in compose file and installed the server without issues now the server is up.

I installed the “intellij idea community edition”, without an issue, after completed my installation I analysis the code using the Sonarlint plugins, and its given the issues from the codes.

But in my SonarQube the dashboard not get reflected, kindly advise if I am missing any things.


Using connection ‘mylocalsonar’ for project ‘ZOOM’
Analysing 13547 files…
Unable to find the quality profile AXkTyd_JnJ1aabZgplo8 in the SonarLint storage. You should update the storage, or ignore this message if the profile is empty.
Unable to find the quality profile AXkRwOendCfllWWqMZ0c in the SonarLint storage. You should update the storage, or ignore this message if the profile is empty.
Unable to find the quality profile AXkRwPSMdCfllWWqMaWZ in the SonarLint storage. You should update the storage, or ignore this message if the profile is empty.
Unable to find the quality profile AXkRwOmqdCfllWWqMZ2Q in the SonarLint storage. You should update the storage, or ignore this message if the profile is empty.
Unable to find the quality profile AXkRwOludCfllWWqMZ1x in the SonarLint storage. You should update the storage, or ignore this message if the profile is empty.
Unable to find the quality profile AXkRwPi7dCfllWWqMadW in the SonarLint storage. You should update the storage, or ignore this message if the profile is empty.
Unable to find the quality profile AXkTyd_JnJ1aabZgplo8 in the SonarLint storage. You should update the storage, or ignore this message if the profile is empty.
Unable to find the quality profile AXkRwOendCfllWWqMZ0c in the SonarLint storage. You should update the storage, or ignore this message if the profile is empty.
Unable to find the quality profile AXkRwPSMdCfllWWqMaWZ in the SonarLint storage. You should update the storage, or ignore this message if the profile is empty.
Unable to find the quality profile AXkRwOmqdCfllWWqMZ2Q in the SonarLint storage. You should update the storage, or ignore this message if the profile is empty.
Unable to find the quality profile AXkRwOludCfllWWqMZ1x in the SonarLint storage. You should update the storage, or ignore this message if the profile is empty.
Unable to find the quality profile AXkRwPi7dCfllWWqMadW in the SonarLint storage. You should update the storage, or ignore this message if the profile is empty.
Found 75656 issues


Thanks,
Sakthivel S

Hi @Sakthivel ,

sonarlint does not trigger a full analysis that would result in a change in SonarQube. It operates as the name suggest as a linter for your code inside your IDE. You need to execute a scan using one of your scanners. you can find more information about that here.

Also please stick to one issue per topic as stated in our FAQ.

Hi @Tobias_Trabelsi

Thanks for your information, I tried to scan my code with SonarScanner for .NET, but I got the below error message in the last step. I have executed the given below 3 steps, but I have an issue with the last step.

Step 1 : SonarScanner.MSBuild.exe begin /k:“ZOOM” /d:sonar.host.url=“http://localhost:9000” /d:sonar.login=“393f6ad2162d414b8514b467d0a4dab391a4cb5d”

Step 2: MsBuild.exe /t:Rebuild

Step 3: SonarScanner.MSBuild.exe end /d:sonar.login=“393f6ad2162d414b8514b467d0a4dab391a4cb5d”

I followed the steps given by the SonarQube, but while executing the 3rd step I have an error message given below. So kindly check and advise.


C:\Users\Administrator\Downloads\sonar-scanner-msbuild-5.2.0.29862-net46>SonarScanner.MSBuild.exe end /d:sonar.login=“393f6ad2162d414b8514b467d0a4dab391a4cb5d”
SonarScanner for MSBuild 5.2
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.
21:30:48.635 The SonarScanner for MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:

  1. The project has not been built - the project must be built in between the begin and end steps
  2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.
  3. The begin, build and end steps have not all been launched from the same folder
  4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)
    21:30:48.638 Generation of the sonar-properties file failed. Unable to complete the analysis.
    21:30:48.654 Post-processing failed. Exit code: 1

Thanks,
Sakthivel S

i will close this thread now. please create a new thread with your issue and include any logs that could be relevant to debug your problem