none
Numeric arithmetic causes truncation when my aplication

    Question

  • I have the next error in the log in my aplication when it try to insert data into Data Base  Microsoft SQL Server Enterprise: Core-based Licensing (64-bit)

    ClassName":"System.Data.SqlTypes.SqlTruncateException","Message":"Numeric arithmetic causes truncation.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":"   at System.Data.SqlClient.TdsParser.TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc, Boolean sync, TaskCompletionSource`1 completion, Int32 startRpc, Int32 startParam)

    Thank


    Adixon

    Thursday, May 16, 2019 7:41 PM

All replies

  • Hi Adixon,

    Is it happening is SSIS?

    What is the source and the destination?

    Please share a screen shot.

    Thursday, May 16, 2019 7:45 PM
  • Hi Yitzhak,

    Is only a App .NET. My app make a calls to a API and put in data into SQL server.

    The app have the next parameter "<add key="BulkSave" value="True"/>" when i active it, i have the next error:

    ""md":"ProcessBatch","msg":"{"Duration":0,"Error":{"ClassName":"System.Data.SqlTypes.SqlTruncateException","Message":"Numeric arithmetic causes truncation.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":"   at System.Data.SqlClient.TdsParser.TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc, Boolean sync, TaskCompletionSource`1 completion, Int32 startRpc, Int32 startParam)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)\r\n   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)\r\n   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()\r\n   at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, IDbTransaction transaction, String sql, Action`2 paramReader, Object obj, Nullable`1 commandTimeout, Nullable`1 commandType)"


    Adixon

    Thursday, May 16, 2019 8:16 PM
  • Hi Adixon,

    it looks like quite eloquently states that the data is longer than can be consumed.

    Whilst I do not know how it is Integration Services related, inspect the data you want to insert versa what SQL Server table column allows.


    Arthur

    MyBlog


    Twitter

    • Proposed as answer by Yang.Z Friday, May 17, 2019 6:58 AM
    Thursday, May 16, 2019 8:44 PM
    Moderator
  • Hi Adixon,

    It is definitely a wrong forum for your issue.

    It looks like your application name is Dapper ORM.

    Generally speaking, you need to check what parameter values are passed by the application.

    It is possible that some of them have calculated values on-the-fly and could be NULLS after the expression is evaluated. Here is a good link on the subject: Arithmetic exception, numeric overflow, or string truncation

    ""md":"ProcessBatch",
    "msg":"{"Duration":0,
    		"Error":{"ClassName":"System.Data.SqlTypes.SqlTruncateException",
    				"Message":"Numeric arithmetic causes truncation.",
    				"Data":null,
    				"InnerException":null,
    				"HelpURL":null,
    				"StackTraceString":"   
    				
    at System.Data.SqlClient.TdsParser.TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, Int32 timeout, Boolean 
    inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc, Boolean sync, 
    TaskCompletionSource`1 completion, Int32 startRpc, Int32 startParam)\r\n   
    
    at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean 
    async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean 
    describeParameterEncryptionRequest)\r\n   
    
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior 
    runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, 
    Boolean asyncWrite, Boolean inRetry)\r\n   
    
    at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 
    completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)\r\n   
    
    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()\r\n   
    
    at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, IDbTransaction 
    transaction, String sql, Action`2 paramReader, Object obj, Nullable`1 commandTimeout, Nullable`1 commandType)"
    • Edited by Yitzhak Khabinsky Thursday, May 16, 2019 9:16 PM
    • Proposed as answer by Yang.Z Friday, May 17, 2019 6:58 AM
    Thursday, May 16, 2019 8:52 PM
  • Hi Yitzhak,

    Is weer, beacuse when i get out the parameters "bulk_save" the aplication inserted into the database, obviusly more slowly because did it one by one. I need to be able to configured bulk parameters.

    Thank.


    Adixon


    • Edited by adix_alex Wednesday, May 22, 2019 3:09 PM Word correction
    Wednesday, May 22, 2019 2:10 PM
  • I find the code. Maybe this help

      }
    
        private void ProcessBatch(IEnumerable<ICDataItem> result)
        {
          Guid empty = Guid.Empty;
          Stopwatch stopwatch1 = Stopwatch.StartNew();
          ClientDynamicParam clientDynamicParam = new ClientDynamicParam(result);
          try
          {
            this.db.Execute("api_bulk_save", (object) clientDynamicParam);
            stopwatch1.Stop();
            Console.WriteLine(string.Format("Total Items {0} - {1}ms", (object) result.Count<ICDataItem>(), (object) stopwatch1.ElapsedMilliseconds));
            Stopwatch stopwatch2 = Stopwatch.StartNew();
            this.proxy.DeleteBatch(result.First<ICDataItem>().BatchID, this.accounts);
            stopwatch2.Stop();
            Console.WriteLine("Delete batch - " + (object) stopwatch2.ElapsedMilliseconds + "ms");
          }
          catch (Exception ex)
          {
            string str = "Error in process batch. ";
            Console.WriteLine(str + ex.Message);
            LogEntry logEntry = new LogEntry()
            {
              Duration = 0,
              Operation = "DATASYNC.PROCESSBATCH",
              Step = OperationStep.Error,
              Message = str,
              Error = ex
            };
            ICApiDataSync.Logger.Log(NLog.LogLevel.Error, logEntry.ToString());
          }
        }


    Adixon

    Wednesday, May 22, 2019 9:45 PM