我们的一个应用程序报告错误消息 2628:
string or binary data would be truncated in table '******', column '******'. Truncated value: '******'
代替
String or binary data would be truncated in table 'mytable', column 'mycolumn'. Truncated value: 'myvalue'.
我用 SSMS 得到的。
我需要更改什么设置才能获得完整的消息?
我试图搜索这个,但我得到的只是我需要将 VERBOSE_TRUNCATION_WARNINGS 设置为 ON,并将 compatibility_level 设置为 150。这是我多年前所做的。
该应用程序具有此错误处理程序:
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("In OnTimer exception ! message: " + ex.Message.ToString());
errorHandler.HandleException(ex, "In OnTimer exception !", ErrorSeverities.Error);
}
errorHandler 看起来像这样
Public Function HandleException(ByVal incommingEx As System.Exception,
ByVal note As String,
ByVal errorSeverity As ErrorSeverities,
Optional ByVal sessionId As String = "",
Optional ByVal applicationSource As String = "",
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 = ""
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 <> "" Then
appSource = applicationSource
End If
'... more code'
messageBuilder.AppendLine("(" + incommingEx.GetType.Name.ToUpper + ")" + vbCrLf + incommingEx.Message + " - SOURCE: " + incommingEx.Source)
'...'
While Not innerEx Is Nothing And innerCount <= 5
messageBuilder.AppendLine("INNER" + Convert.ToString(innerCount) + " (" + innerEx.GetType.Name.ToUpper + "):" + vbCrLf + **innerEx.Message** + " - SOURCE: " + innerEx.Source)
If Not innerEx Is Nothing AndAlso Not innerEx.StackTrace Is Nothing Then
stackTraceBuilder.AppendLine("INNER" + Convert.ToString(innerCount) + ": " + 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
我们以前没有看到过这种行为,但我们最近将 .net 框架更新到了 4.7.2 版本,所以它可能是相关的。
错误文本“字符串或二进制”来自该位
- innerEx.Message + 那是一个简单的内置异常数据类型。因此,构建字符串的是 VB 和/或 .net 和/或 SQL Server,而不是我们。
该错误发生在调用存储过程之后,用户可能在其中输入了 varchar(1000) 文本。存储过程增加了一点,表没有空间容纳所有 1100 个字节。因此错误。存储过程没有 try-catch 块。