How is your experience with the OutSystems Community?
46
Views
12
Comments
Solved
Database exception - String or binary data would be truncated.
Question

Hi Folks,

A database exception is occurring while saving the record, please see details below

"String or binary data would be truncated in table 'OSPRD.dbo.TableName', column 'CARDNUMBER'. Truncated value: '52266122'.
The statement has been terminated. "

Please note: 
Datatype of attribute CARDNUMBER is Text of length 8.

Even though the attribute length is 8 and valid data is being passed that is passing a value of length 8 and no extra spaces; however a database thrown exception. 

I would appreciate your assistance!

Thanks


2026-03-20 01-28-51
Saugat Biswas
Solution

Hi @Meer Imtiyaz Ali,

One more observation from your error message.

Just going by the English Language. The message says Truncated Value: '52266122'. Emphasis on Truncated Value.

Is it possible the user has provided more than 8 characters and error message displays only the truncated value.

Can you add log messages for card number before saving to DB, so you can verify if actually correct cardnumber length was sent when the error occurred. 

Cheers,

Saugat

2019-04-02 11-48-16
Martin Rozeboom

Can you provide us with some context? What are the data types of the input as well as the expectation? Do you use the standard CreateOrUpdate-action of OutSystems? 

2019-09-11 10-03-50
Meer Imtiyaz Ali

Datatype is Text with length 8.

Yes, using standard CreateOrUpdate-action of OutSystems.

Here scenario is, application captures an 8-digit input from the user and save it to DB.

2026-01-28 16-57-48
Mihai Melencu
Champion

Hi @Meer Imtiyaz Ali ,

Does this issue occur across all environments? Is the entity external or internal? Also, was the attribute length recently updated? 

2019-09-11 10-03-50
Meer Imtiyaz Ali

HI Mihai Melencu ,
The exception occurs only in the production environment and is not reproducible in lower environments.

2026-01-28 16-57-48
Mihai Melencu
Champion

If the issue only occurs in PROD and the entity is internal,  can you check if the version in prod has the right max length. Also you could do a republish and see if the issue persists. 

2024-10-05 13-30-20
Huy Hoang The

Hi @Meer Imtiyaz Ali ,

If the issue occurs in the production environment (Prod), then there is definitely a difference between the source code in the development environment (Dev) and the production environment. You need to double-check. 

For O11 you can open Prod environment

For ODC you can check revison on Prod.

2026-03-20 01-28-51
Saugat Biswas

Hi @Meer Imtiyaz Ali
Your error seems a bit tricky. 

Even though CARDNUMBER is Text(8) in OutSystems and you are passing exactly 8 characters, SQL Server is rejecting it because the physical database column length is smaller than 8.

OutSystems does not dynamically enforce the database schema at runtime. What matters is the actual SQL column definition, not what Service Studio shows. So this error means one of the following is true:

  1. Database schema mismatch (schema drift) 
    • The column was originally created as VARCHAR(6) or VARCHAR(7) 
    • Later changed to Text(8) in OutSystems 
    • The module was never successfully published to update the DB
  2. Manual database change 
    • Someone altered the table directly in SQL Server 
    • OutSystems metadata no longer matches the DB
  3. Production != Dev schema 
    • Dev works 
    • Prod column is smaller
  4. Trigger writing to another table 
    • Insert succeeds in Table 
    • A Trigger inserts CARDNUMBER into another table with smaller length 
    • SQL Server still reports the original table

Please validate each scenario and confirm everything is as expected.

Hope this helps,

Cheers,

Saugat

2025-12-29 06-17-15
Deepak Raj M

hi @Meer Imtiyaz Ali if you are fetching data from an external source, for example SQL, then this error is coming from there — you have to check that first." 

2019-09-11 10-03-50
Meer Imtiyaz Ali

Thank you all for your responses!

However,  the database attribute length is the same in both lower and Production environments.

This issue is intermittent and occurs only for certain records. The issue does not reproduce even when the same data is used.

Is it possible that something is getting injected during the submission process?


2026-03-20 01-28-51
Saugat Biswas
Solution

Hi @Meer Imtiyaz Ali,

One more observation from your error message.

Just going by the English Language. The message says Truncated Value: '52266122'. Emphasis on Truncated Value.

Is it possible the user has provided more than 8 characters and error message displays only the truncated value.

Can you add log messages for card number before saving to DB, so you can verify if actually correct cardnumber length was sent when the error occurred. 

Cheers,

Saugat

2019-09-11 10-03-50
Meer Imtiyaz Ali

Validation is enforced at the UI end and input field does not accept more than 8 characters.

@Saugat Biswas : You're right, data seems to be getting truncated, which suggests that some extra characters may be appended. That seems valid.

I have set up logs in the lower environment, but I need to wait for the production deployment, after which we will continue and share an update.

Many thanks to all of you for your help.

2019-09-11 10-03-50
Meer Imtiyaz Ali

Hello everyone,

I enabled logging in Production and, during testing, discovered that some malicious data was being truncated, which caused this issue. After sanitizing the CardNumber field, the issue is resolved. 

A big thank you to everyone for your support and assistance in helping resolve this issue.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.