SonarQube SQL Error – String or binary data would be truncated

New day and a new issue with the SonarQube setup. Yesterday I documented the error and fix relating to an issue I faced while integrating SonarQube with the TFS Build.

SonarQube Error – End of Central Directory record could not be found

Moving a step ahead, I encountered another issue, where the Begin Analysis Task was not able to complete processing. 

The SonarQube Scanner for MSBuild – Begin Analysis task contacts the SonarQube server to retrieve the quality profile, and dynamically produces rulesets to be applied during the static analysis. It also sets things up so that the following MSBuild steps produce some data to prepare the analysis.

If there are issues in the process, I would recommend to go the Administration section in your SonarQube server, and navigate to the background Tasks tab.

Background Tasks

SonarQube Scanner

Background Tasks page allows monitoring of the queue of tasks running asynchronously on the server. It also gives access to the history of finished tasks and their status. Analysis report processing is the most common kind of background task.

Click the ‘Show Error Details‘ button to view the error logs and you should be able to easily troubleshoot the root cause of the failure.

SonarQube Error Details

Looking at the error logs, I found a database error – String or binary data would be truncated. 

This error was being thrown while inserting into the snapshots table in the SonarQube database. It is actually a very common error which is thrown when you try to insert any data in string (varchar,nvarchar,char,nchar) data type column which is more than size of the defined column in the table.

Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error updating database.  Cause: String or binary data would be truncated.### The error may involve org.sonar.db.component.SnapshotMapper.insert-Inline### The error occurred while setting parameters### SQL: insert into snapshots (     uuid,     component_uuid,     created_at,     build_date,     status,     purge_status,     islast,     version,     period1_mode,     period1_param,     period1_date)     values (     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?,     ?)### Cause: String or binary data would be truncated.

Background Task SonarQube Error

Looking at the table schema, the immediate thing which caught my attention was the bunch of period_mode and period_param columns which have size defined as NVARCHAR(100) – and might be candidates which can throw this error —

CREATE TABLE [dbo].[snapshots](
[status] [NVARCHAR](4) NOT NULL,
[islast] [BIT] NOT NULL,
[version] [NVARCHAR](500) NULL,
[purge_status] [INT] NULL,
[period1_mode] [NVARCHAR](100) NULL,
[period1_param] [NVARCHAR](100) NULL,
[period2_mode] [NVARCHAR](100) NULL,
[period2_param] [NVARCHAR](100) NULL,
[period3_mode] [NVARCHAR](100) NULL,
[period3_param] [NVARCHAR](100) NULL,
[period4_mode] [NVARCHAR](100) NULL,
[period4_param] [NVARCHAR](100) NULL,
[period5_mode] [NVARCHAR](100) NULL,
[period5_param] [NVARCHAR](100) NULL,
[created_at] [BIGINT] NULL,
[build_date] [BIGINT] NULL,
[period1_date] [BIGINT] NULL,
[period2_date] [BIGINT] NULL,
[period3_date] [BIGINT] NULL,
[period4_date] [BIGINT] NULL,
[period5_date] [BIGINT] NULL,
[component_uuid] [NVARCHAR](50) NOT NULL,
[uuid] [NVARCHAR](50) NOT NULL,
[id] ASC

Using SQL Profiler, I recreated the issue and was able to confirm that the datatype on period1_param column was the culprit. I increased the size to NVARCHAR(500) on these columns and the data started getting saved successfully to the table.

Increase column size

This helped me to resolve the error – String or binary data would be truncated.
I will go ahead and report this issue to the SonarQube Team so that they can address this as part of their upcoming updates.

In case you have any other questions or face any other issues while installing SonarQube or upgrading it to a new version, please feel free to post a comment below and I would be happy to help.

Categories: C#, SonarQube, SQL Server, Visual Studio

Tags: , ,

3 replies

    • This is awesome. Thanks Ann for your prompt response on the issues and the quick turn around in fixing them. For those who have not tried out SonarQube, you SHOULD. You can ensure high Code Quality in your projects and also automate lot of your Code Review efforts.



  1. 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: Logo

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

Facebook photo

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

Connecting to %s

%d bloggers like this: