Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I connected sql server of other system thanks to originalgriff.
but when I tried to run my application it is connected to that system SQL and next error is coming "
Arithmetic overflow error converting numeric to data type numeric.

If I ran that application from my system it is running without any error.Is there any solution for this.

What I have tried:

I googled but came with not suitable solution
Posted
Updated 6-Oct-17 5:02am
Comments
Richard MacCutchan 6-Oct-17 10:38am    
What are the variables and their values that cause this error?
vijay_bale 6-Oct-17 10:49am    
I gave connection string in appconfig file like below
<add name="connectionstr"
connectionString="Password=test1234;Persist Security Info=True;User ID=test;Initial Catalog=inventoryDB;Data Source=m3\SQL2016"
providerName="System.Data.SqlClient" />

And I am reading this like below

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstr"].ConnectionString);

When I ran this, databse is connecting, but error is coming "Arithmetic overflow error converting numeric to data type numeric."
Richard MacCutchan 6-Oct-17 11:00am    
Sorry but that does not help. You need to use your debugger to find exactly where the error occurs and what are the values that cause it.
Patrice T 6-Oct-17 17:58pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.

The solution is very simple. Your data is different and some number is too big which is why you are getting an overflow error. You'll have to see what exact data is being dealt with and fix it.
 
Share this answer
 
Comments
vijay_bale 6-Oct-17 10:53am    
that same application with same data i am running in my system and everything is running fine.
ZurdoDev 6-Oct-17 10:59am    
Well clearly something is not the same or else they would work the same. But either way, there is no way we can see your systems to tell you what is different. You'll have to examine the data and table structures to see where the error is coming from. It's not that hard if you know what sql is causing the error.
Quote:
that same application with same data i am running in my system and everything is running fine.

Then you need to start looking at what is different.
Assuming you can't use the debugger on the system where it id failing, you will need to manually add logging info to your application to narrow down exactly where the error is occurring, and then concentrate logging there to find out what data you are talking about, and how it different from the same run on your system.

Try logging to a file with File.AppendLine and compare the outputs of the two systems: look for where they differ and compare that with the code.

We can't do any of that for you: we don;t have access to either computer, or any idea what your code or data look like!
 
Share this answer
 
Comments
vijay_bale 6-Oct-17 13:00pm    
it is showing error near some stored procedures which i am using to display data and update some data. Below one of the stored procedures I am pasting

USE [inventoryDB]
GO
/****** Object: StoredProcedure [dbo].[StockUpdate] Script Date: 06-10-2017 09:44:41 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[StockUpdate]
@SearchParam VARCHAR(MAX) =''

AS
SET NOCOUNT ON

DECLARE @SqlString VARCHAR(MAX)


SET @SqlString ='
select fullname,
ItemId,
SUM(PurchaseQty) AS [PurchaseQty],
SUM(SalesQty) AS [SalesQty]
From (
select fullname,
ItemId,
SUM(itmqty) AS [PurchaseQty],
SUM(0.000) AS [SalesQty]
from invDB WITH(NOLOCK)
LEFT JOIN itemDB WITH(NOLOCK) ON itemDB.itmcode=invDB.ItemId
Group By fullname,ItemId

UNION

select fullname,
ItemId,
SUM(0.000) AS [PurchaseQty],
SUM(itmqty) AS [SalesQty]
from salesDB WITH(NOLOCK)
LEFT JOIN itemDB WITH(NOLOCK) ON itemDB.itmcode=salesDB.ItemId
Group By fullname,ItemId)a Group By fullname,ItemId
'

IF LTRIM ( RTRIM ( @SearchParam ) ) <> ''
BEGIN
EXEC (@SqlString + ' WHERE ' + @SearchParam )

END
ELSE
BEGIN
EXEC (@SqlString)
PRINT (@SqlString)
END

PRINT @SqlString + ' WHERE ' + @SearchParam
Patrice T 6-Oct-17 17:58pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.
Atlapure Ambrish 6-Oct-17 13:55pm    
Can you remove sum(0.000) from both queries and check if it is not throwing that error after tweaking the query as required.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900