Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
Hello Friends

I'm using Visual Web Developer Express 2005.
And when I am running my application this is returning the exception.
I tried but didn't get the solution. And my app is running on Windows Server 2008.

help me to overcome this. I couldn't understand what exactly the error is.


Code
C#
Int32 east_Count = 0;
            Int32 west_Count = 0;
            Int32 north_Count = 0;
            Int32 madurai_Count = 0;
            string prefixQuery = "SELECT COUNT(*) FROM ";
            string postfixQuery = " WHERE MESSAGE='T2B' AND TRNDATE LIKE Concat(CONVERT(now(),date),'%')";
            using (OdbcCommand cmd = new OdbcCommand())
            {
                cmd.Connection = con;
                con.Open();

                cmd.CommandText = prefixQuery + "inbox_east" + postfixQuery;
                east_Count = Convert.ToInt32(cmd.ExecuteScalar());
                cmd.CommandText = prefixQuery + "inbox_east_master" + postfixQuery;
                east_Count += Convert.ToInt32(cmd.ExecuteScalar());
                               con.Close();

                lblEast.Text = east_Count.ToString();

            }
        }
        catch (Exception ex)
        {
            using (TextWriter tw = new StreamWriter(@"E:\Logs\Check.txt", true))
            {
                tw.WriteLine("=======Start======");
                tw.WriteLine(DateTime.Now.ToString());
                tw.WriteLine(ex.ToString());
                tw.WriteLine("=======End======");
            }
        }
        finally
        {
            con.Close();
        }
    }


Exception occurring

System.OverflowException: Arithmetic operation resulted in an overflow.
at System.Data.Odbc.OdbcDataReader.GetSqlType(Int32 i)
at System.Data.Odbc.OdbcDataReader.GetValue(Int32 i)
at System.Data.Odbc.OdbcCommand.ExecuteScalar()




I couldn't find answer If this is running on my local machine then its working but when running on windows server 2008 exceptions are coming
Posted
Updated 27-Apr-17 3:04am
v4

Below link will give you details around System.OverflowException.
OverflowException Class

Most probably your code throwing Exception on either of below lines.
east_Count = Convert.ToInt32(cmd.ExecuteScalar());
OR
east_Count += Convert.ToInt32(cmd.ExecuteScalar());<br />


Debug your code and see what values you are getting from cmd.ExecuteScalar().

Also check, How many records you get when you execute your queries in MySQL Database Editor.
 
Share this answer
 
Comments
Manish Kumar Namdev 3-Sep-11 6:09am    
I Check this one which you suggested
RaisKazi 3-Sep-11 6:16am    
Ok. So what's the result?
RaviRanjanKr 4-Sep-11 0:08am    
Interesting Answer, My 5+
RaisKazi 4-Sep-11 2:23am    
Thank you.
your result may be resulting in bigger value and overflow datatype limits.
try with following
C#
Int64 east_Count =0;
 
Share this answer
 
Comments
Manish Kumar Namdev 3-Sep-11 6:09am    
I did the same you suggested it wasn't working

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