ExecuteNonQuery() from c# throwing exception - arithmetic overflow error converting numeric to data type numeric

0

I have a weird situation, I have a SP being called from my C# application through ADO.Net, the SP doesn't return any data. It is throwing the below exception, but when i execute the SP with the same parameters in SSMS it runs with out any issues.

There is no other actions apart from calling the SP in my C# code.

Error: System.Data.SqlClient.SqlException (0x80131904): Arithmetic overflow error for type int, value = 2344000000.000000

IN C# code the SP is called using ExecuteNonQuery() and it throws Arithematic overflow exception.

I changed it to ExecuteScalar() and there is no error, which i could confirm that the issue is with either sql server or ADO.Net as SP execution in SSMS always executed without any issues.

As the SP doesn't return any data, ADO.NET ExecuteNonQuery will get the number of rows affected as return value and may be this number is bigger than Power(2,31) and could be the reason of Arithematic overflow exception but i don't have more than Power(2,31) rows in my DB tables. This is just my guess.

c#
sql-server
ado.net
asked on Stack Overflow Mar 28, 2019 by Harinath Boyapalli • edited Mar 28, 2019 by Harinath Boyapalli

1 Answer

0

This means the value is too big for int type so it overflows

the max value for signed int is 2,147,483,647

so 2344000000 will return this error

answered on Stack Overflow Mar 28, 2019 by Dung Le

User contributions licensed under CC BY-SA 3.0