string or binary data would be truncated in table '******', column '******'. Truncated value: '******' One of our applications report on error message 2628:
string or binary data would be truncated in table '******', column '******'. Truncated value: '******'
instead of
String or binary data would be truncated in table 'mytable', column 'mycolumn'. Truncated value: 'myvalue'.
which I get with SSMS.
What setting do I need to change to get the full message?
I've tried to search for this, but all I get is that I need to set VERBOSE_TRUNCATION_WARNINGS to ON and compatibility_level to 150.
Which I've done ages ago.
The application has this error handler:
 try
     {
         ES.isWorking = true;
         Worker worker = new Worker(new DBConnection(Settings.ConnectionString));
         worker.DoWork();
         ES.isWorking = false;
     }
 catch (Exception ex)
     {
         ES.isWorking = false;
         this.eventLog.WriteEntry(&quot;In OnTimer exception ! message: &quot; + ex.Message.ToString());
         errorHandler.HandleException(ex, &quot;In OnTimer exception !&quot;, ErrorSeverities.Error);
     }

The errorHandler looks like this
Public Function HandleException(ByVal incommingEx As System.Exception,
                                   ByVal note As String,
                                   ByVal errorSeverity As ErrorSeverities,
                                   Optional ByVal sessionId As String = &quot;&quot;,
                                   Optional ByVal applicationSource As String = &quot;&quot;,
                                   Optional ByVal ignoreDB As Boolean = False,
                                   Optional ByVal noMail As Boolean = False) As Integer
    Dim stackTraceBuilder As New System.Text.StringBuilder
    Dim targetSite As String = &quot;&quot;
    Dim errorTime As DateTime = Now
    Dim messageBuilder As New System.Text.StringBuilder
    Dim innerEx As Exception = incommingEx.InnerException
    Dim errorId As Integer = 0
    Dim innerCount As Integer = 1
    Dim loggedToDb As Boolean = False
    Dim appSource As String = Me._applicationSource
    If applicationSource &lt;&gt; &quot;&quot; Then
        appSource = applicationSource
    End If
    '... more code'

    messageBuilder.AppendLine(&quot;(&quot; + incommingEx.GetType.Name.ToUpper + &quot;)&quot; + vbCrLf + incommingEx.Message + &quot; - SOURCE: &quot; + incommingEx.Source)
    '...'
    While Not innerEx Is Nothing And innerCount &lt;= 5
        messageBuilder.AppendLine(&quot;INNER&quot; + Convert.ToString(innerCount) + &quot; (&quot; + innerEx.GetType.Name.ToUpper + &quot;):&quot; + vbCrLf + **innerEx.Message** + &quot; - SOURCE: &quot; + innerEx.Source)
        If Not innerEx Is Nothing AndAlso Not innerEx.StackTrace Is Nothing Then
            stackTraceBuilder.AppendLine(&quot;INNER&quot; + Convert.ToString(innerCount) + &quot;: &quot; + innerEx.StackTrace) 'Me.GetNumberedStack(innerEx))
        End If
        innerEx = innerEx.InnerException
        innerCount += 1
    End While
    '... more code where the error message is inserted in a log table, via a sproc'
End Function

We have not seen this behavior before, but we have recently updated the .net framework to version 4.7.2, so it could be related.
the error text &quot;string or binary&quot; is comming from the bit that goes

innerEx.Message +
and that is a simple built-in Exception data type. So it is VB and/or .net and/or SQL Server that is building the string, not us.

The error comes after a call to a stored procedure, where the user has probably entered a varchar(1000) text. The stored procedure adds a bit more, and the table hasn't got room for all 1100 bytes. Hence the error.
The stored procedure does not have a try-catch block.
It looks like this table was defined with dynamic data masking, and the user that the application uses to access the database doesn't have permission to view masked data (which is good!).
This is why the behavior differs between the application and SSMS: I expect you're using a higher-privileged user when running the query from SSMS
Here's a demo:
CREATE TABLE dbo.Test
(
    Id int IDENTITY PRIMARY KEY,
    Filler varchar(100) MASKED WITH (FUNCTION = 'partial(1,&quot;XXXXXXX&quot;,0)') NULL
);
GO

CREATE USER TestUser WITHOUT LOGIN;  
GRANT SELECT ON dbo.Test TO TestUser;  
GRANT INSERT ON dbo.Test TO TestUser;
GO

EXECUTE AS USER = 'TestUser';
INSERT dbo.Test 
    (Filler)
VALUES
    (REPLICATE(N'A', 101)); 
REVERT;

The result of which is:
Msg 2628, Level 16, State 1, Line 12
String or binary data would be truncated in table '******', column '******'. Truncated value: '******'.

To get the full message in the application, you'll need to grant the user the UNMASK permission:
GRANT UNMASK TO TestUser;

Running the INSERT code again results in the full error text:
Msg 2628, Level 16, State 1, Line 14
String or binary data would be truncated in table 'tempdb.dbo.Test', column 'Filler'. Truncated value: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'.


When using Azure SQL Database, Dynamic Data Masking can also be configured in the Azure Portal user interface.  You may want to check there (although as far as I can tell, masks set up this way still update the sys.columns metadata):

I would also check if there are other databases that are part of the same logical SQL Server instance in Azure - maybe there are some kind of strange, cross-database queries going on.