SonarQube 6.5 – Issues while configuring SQL Server Database


Code Quality plays an integral part in Software Development life cycle. The earlier we identify issues in the process, the easier and cheaper it is to address them. With the combination of Unit Tests and Static Code Analysis, developers can get an early feedback for their code changes. Tools like SonarQube are an easy way to identify anti-patterns in your code base and should be run regularly to improve overall quality of code, adhere to good practices and keep your technical debt in check.

If you want to learn more about SonarQube, you can refer an earlier blog which I wrote –Manage your Technical Debt with Visual Studio 2015 and SonarQube

Problem Statement

I installed the latest version of SonarQube 6.5 from the website –
https://www.sonarqube.org/downloads/

I was able to get the SonarQube server up and running in no time. However I struggled configuring my SQL Server database and letting it save results into the SQL Server tables.

I followed the steps mentioned here to configure my SQL Database –https://docs.sonarqube.org/display/SONAR/Installing+the+Server

I have my SQL Server database named ‘Sonar’ created with a user named ‘SonarUser’ and have given it admin rights.
I changed the collation to be case-sensitive (CS) and accent-sensitive (AS). I also downloaded the correct version of the jdbc driver and put it in the correct folders.

However I was not able to make either Windows Authentication or SQL Server Authentication to work. The database was still empty, and did not see the tables/indexes in there.

I made the below changes to the ‘sonar.properties’ file – 1 at a time – but neither worked.

SQL Authentication
sonar.jdbc.username=SonarUser sonar.jdbc.password=***** sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=Sonar

Windows Authentication
sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=Sonar; integratedSecurity=true

When I make any change to the ‘sonar.properties’ file and then start the Sonar Server, it fails with the following error –

2017.10.03 16:59:09 INFO app[][o.s.a.AppFileSystem] Cleaning or creating temp directory C:\Sonarqube-6.5\temp 2017.10.03 16:59:09 INFO app[][o.s.a.p.JavaProcessLauncherImpl] Launch process[es]: C:\Program Files\Java\jre1.8.0_101\bin\java -Djava.awt.headless=true -Xmx1G -Xms256m -Xss256k -Djna.nosys=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -Djava.io.tmpdir=C:\Sonarqube-6.5\temp -cp ./lib/common/;./lib/search/org.sonar.search.SearchServer C:\Sonarqube-6.5\temp\sq-process1211130103830390174properties 2017.10.03 16:59:19 INFO app[][o.s.a.SchedulerImpl] Process[es] is up 2017.10.03 16:59:19 INFO app[][o.s.a.p.JavaProcessLauncherImpl] Launch process[web]: C:\Program Files\Java\jre1.8.0_101\bin\java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -Djava.io.tmpdir=C:\Sonarqube-6.5\temp -cp ./lib/common/;./lib/server/;C:\Sonarqube-6.5\lib\jdbc\mssql\mssql-jdbc-6.1.0.jre8.jar org.sonar.server.app.WebServer C:\Sonarqube-6.5\temp\sq-process7396503632227644033properties 2017.10.03 16:59:23 INFO app[][o.s.a.SchedulerImpl] Process [web] is stopped 2017.10.03 16:59:24 INFO app[][o.s.a.SchedulerImpl] Process [es] is stopped 2017.10.03 16:59:24 INFO app[][o.s.a.SchedulerImpl] SonarQube is stopped <– Wrapper Stopped

I also noticed that if I undo the changes in ‘sonar.properties’ file, and run the StartSonar.bat – the server runs fine.

Troubleshooting the Problem

SonarQube is stopped <– Wrapper Stopped

The above line is not a helpful error message and provides no information at all.

Then I looked at the Sonar.log file stored in the installation folder – C:\Sonarqube-6.5\logs

2017.10.03 08:45:19 INFO app[][o.s.a.SchedulerImpl] Process [web] is stopped
2017.10.03 08:45:20 INFO app[][o.s.a.SchedulerImpl] Process [es] is stopped
2017.10.03 08:45:20 INFO app[][o.s.a.SchedulerImpl] SonarQube is stopped
<– Wrapper Stopped
–> Wrapper Started as Console
Launching a JVM…
Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved.

That did not provide any helpful information either.

A pro-tip is here to not just focus on the sonar.log file but to also look at all the generated log files in the installation folder – C:\Sonarqube-6.5\logs – and especially the web.log file.

web log SonarQube

Once I started looking at the web.log file, I was able to identify the root cause of this error —

2017.10.03 08:40:51 INFO web[][o.sonar.db.Database] Create JDBC data source for jdbc:sqlserver://localhost;databaseName=SonarQube;integratedSecurity=true
2017.10.03 08:40:51 ERROR web[][o.s.s.p.Platform] Web server startup failed: Unsupported mssql version: 10.0. Minimal supported version is 11.0.
2017.10.03 08:40:51 WARN web[][o.a.c.l.WebappClassLoaderBase] The web application [ROOT] appears to have started a thread named [elasticsearch[Ivan Kragoff][[timer]]] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Thread.sleep(Native Method)
org.elasticsearch.threadpool.ThreadPool$EstimatedTimeThread.run(ThreadPool.java:747)

The error message indicated that I was using an unsupported SQL version in my local. I quickly ran the below query to confirm —

SELECT @@VERSION AS ‘SQL Server Version’;

Figured out that I was running the SQL Express 2008 version locally.

Microsoft SQL Server 2008 (SP1) – (X64) Copyright (c) 1988-2008 Microsoft Corporation Express Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)

I had a SQL Server 2014 instance running locally too. So, I created the Sonar database and the associated changes in the SQL Server 2014 instance. Once I did that and restarted the SonarQube engine, the process started back up and so did my SonarQube server.

Microsoft SQL Server 2014 (SP2) (Intel X86) Copyright (c) Microsoft Corporation Developer Edition on Windows NT 6.1 <X64> (Build 7601: ) (WOW64)

Basically I was running an older version of SQL Server, which was causing this error.
Once I created a database in SQL Server 2014 with this above steps, I was able to run the SonarQube instance without any issues. I am pretty sure that the newer version of SonarQube has this pre-requisite of running with SQL Server  2012 or later – the earlier version of SonarQube did not have that. 

The new tables were created —

SonarQube Tables

Using the Object Explorer Details window, you can confirm that there are records inserted into the tables as you run SonarQube against your projects —

SonarQube RowCount

Conclusion – 

You might bump into multiple errors while configuring SonarQube in your project. Make sure to review the log files to get more insight into those error. Not just the sonar.log, but all the log files in your installation directory – C:\Sonarqube-6.5\logs – and especially the web.log file.



Categories: C#, SonarQube, SQL Server

3 replies

  1. Hi thanks for the information. I just want to add on one more thing that SonarQube 6.7 supports SQL Server 2014 or higher.

    Like

Trackbacks

  1. SonarQube Error – End of Central Directory record could not be found – dotnetvibes
  2. SonarQube 6.5 – Code Coverage Result is not displayed – dotnetvibes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: