How to install SQL Server database for SonarQube

Overview

SonarQube has an inbuilt database which is meant for evaluation purpose. When we start using SonarQube on the project, we should switch to one of the databases supported by SonarQube.

Here we will discuss how to setup SQL server database for SonarQube. To write our sample code, we will use SQL Server Express Edition 2019.

Learn more about SonarQube:

👉 How to Install SonarQube 9 on windows with tips for troubleshooting

👉 SonarQube integration with Jenkins

👉 To read other posts regarding SonarQube Click here

Install SQL Server

Let us start with downloading the SQL Server Express Edition 2019 database from Microsoft website.

Once we are done installing the database, we will also need Microsoft SQL Server Management Studio. 

We will download it from Microsoft website and install. You can just search to download it. This is the download link for MSSMS at the time of writing this article.

Configurations

Once the installation is complete, we will go to SQL Server Configuration Manager.

Go to SQL Server Network Configuration -> Protocols for SQLEXPRESS

Then Select TCP IP. Mark Enabled=Yes

Then go to IP Addresses tab -> IPALL -> TCP Port = 1433

SQL Server Configuration Manager

Create New Login

Now go to Start Menu and open Microsoft SQL Server Management Studio.

Select the Server Name. Select default windows authentication.

Open the Object Explorer.

Next open Security folder in the Object Explorer

Right click on Logins. Select New Login… from the right menu.

Open New Login Screen

On the new login screen create a new user with a Login Name and a password. We will create a user with Login Name as sonar with SQL Server authentication as seen above. 

Create New Login: sonar

Create New Database

Once, the login is created, Disconnect. Then reconnect the server by clicking on Connect using the new credentials. Right click the Databases folder and select New Database… 

Microsoft SQL Server Management Studio

In the new screen provide Database Name. We will provide the name as SonarDB. You can provide any name of your choice. We will keep the remaining parameters as default and select the OK button.

The new database name will shown under Databases in the Object Explorer.

New Database SonarDB is created

Right click SonarDB database to select Database Properties.

Open Database Properties

Select the correct collation. It should be case sensitive (cs) and accent sensitive (as) as shown below. 

Select Case Sensitive and Accent Sensitive Collation

JDBC Driver

Now download the JDBC driver from Microsoft website. This is the download link for JDBC driver at Microsoft site at the time of writing this article.

After downloading JDBC driver, go to sonar.properties file in the conf folder. Uncomment the section with JDBC user and password

sonar.jdbc.username

sonar.jdbc.password

We will update the user as sonar and provide the password. 

Now under SQL Server, look for JDBC url. Uncomment the url after changing database name to SonarDB. We will also use localhost as the server location for SQL Server as our server is installed locally. In our case this becomes :

sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=SonarDB

Start the SQL Server service. Also start/restart the SonarQube service and open SonarQube in browser. SonarQube should now start use SQL Server database.

Conclusion

In this post, we have downloaded, installed, configured SQL Server to create a database with SQL server authentication. Then we updated sonar.properties file to configure SonarQube to use the SQL Server database we have created.

Let us know if you found this post helpful.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *