An overflow occurred due to an arithmetic operation.

asp.net entity-framework mysql

Question

My c# basic database class abruptly stopped functioning after upgrading my website on ii7 on Window Server 2008 from Framework 3.5 to Work with Framework 4. The issue message was "Arithmetic operation led in an overflow." I'm using a separate server to access the MySQL server.

I was quite disappointed to return to Framework 3.5 after failing to discover a solution.

Here are some of the logs I have for this problem on my server's event viewer:


Information processing: 3680 Process ID named process: w3wp.exe the NT AUTHORITYNETWORK SERVICE account

Information on exceptions Type of exception: Overflow Exception Arithmetic operation produced an overflow, which is an exception. during DataAccess. ExecuteStringQuery(String strSQL) is located at camsBaseShowWeb.OnPreInit(EventArgs e) in camsBaseShowWeb.cs:line 134 at System.Web.UI.Page in d:webSitess2sApp CodeDBDataAccess.cs:line 214 at DataSelect.generalString(String rowName, String tablename, String idName, String PerformPreInit()

on the System.Web.UI.Page.ProcessRequestMain page (Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

grateful for any assistance.


No matter whatever function I attempt to call from this code, I get this error.

This is my code:

using System;
using System.Data;
//using Microsoft.Data.Odbc;
using System.Data.Odbc;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public class DataAccess
{
    #region Private Variables
    private static DataAccess _DataAccess = null;
    private static object _SyncLock = new object();
    private string _strCon = "Driver={MySQL ODBC 5.1 Driver};Server=theIP;Database=theDatabase; UID=root;Password=thePassword;Option=3;";
    private OdbcConnection myConnection = null;
    #endregion

    #region Instance Method
    public static DataAccess Instance
    {
        get
        {
            lock (_SyncLock)
            {
                if (_DataAccess == null)
                    _DataAccess = new DataAccess();
                return _DataAccess;
            }
        }
    }
    #endregion

    #region Constractors
    public DataAccess()
    {
        myConnection = new OdbcConnection(_strCon);
        myConnection.Open();
    }
    #endregion

    #region Public Functions
    public OdbcDataReader ExecuteQueryReader(string strSQL)
    {
        try
        {
            OdbcCommand myCommand = new OdbcCommand(strSQL, myConnection);
            return myCommand.ExecuteReader();
        }
        catch (Exception ex)
        {
            if (Dict.IsRemote == true)
            {
                sendMail("error ExecuteQueryReader SQL s2s", strSQL, ex);
            }
            throw ex;
        }
    }

    public DataTable ExecuteQuery(string strSQL)
    {
        DataTable dt = new DataTable();
        OdbcDataAdapter objDataAdapter = null;
        try
        {
            objDataAdapter = new OdbcDataAdapter(strSQL, myConnection);
            objDataAdapter.Fill(dt);
        }
        catch (Exception ex)
        {
            if (Dict.IsRemote == true)
            {
                sendMail("error ExecuteQuery SQL s2s", strSQL, ex);
            }

            throw ex;
        }
        finally
        {
            if (objDataAdapter != null) objDataAdapter.Dispose();
        }
        return dt;
    }

    public DataView ExecuteQueryDV(string strSQL)
    {
        DataTable dt = new DataTable();
        OdbcDataAdapter objDataAdapter = null;
        try
        {
            objDataAdapter = new OdbcDataAdapter(strSQL, myConnection);
            objDataAdapter.Fill(dt);
        }
        catch (Exception ex)
        {
            if (Dict.IsRemote == true)
            {
                sendMail("error ExecuteQuery SQL s2s", strSQL, ex);
            }

            throw ex;
        }
        finally
        {
            if (objDataAdapter != null) objDataAdapter.Dispose();
        }
        return new DataView(dt);
    }

    public DataTable ExecuteLimitedQuery(string strSQL, int startRow, int rowNum)
    {
        DataTable dt;
        DataSet ds = new DataSet();
        OdbcDataAdapter objDataAdapter = null;
        try
        {
            objDataAdapter = new OdbcDataAdapter(strSQL, myConnection);
            objDataAdapter.Fill(ds, startRow, rowNum, "rowTable");
            dt = (DataTable)ds.Tables["rowTable"];
        }
        catch (Exception ex)
        {
            if (Dict.IsRemote == true)
            {
                sendMail("error ExecuteLimitedQuery SQL s2s", strSQL, ex);
            }

            throw ex;
        }
        finally
        {
            if (objDataAdapter != null) objDataAdapter.Dispose();
        }
        return dt;
    }

    public object ExecuteScalarQuery(string strSQL)
    {
        OdbcCommand myCommand = null;
        object obj = null;

        try
        {
            myCommand = new OdbcCommand(strSQL, myConnection);
            obj = myCommand.ExecuteScalar();
        }
        catch (Exception ex)
        {  
            if (Dict.IsRemote == true)
            {
                sendMail("error ExecuteScalarQuery SQL s2s", strSQL, ex);
            }

            throw ex; 
        }
        finally
        {
            if (myCommand != null) myCommand.Dispose();  
        }

        return obj;
    }

    public string ExecuteStringQuery(string strSQL)
    {
        OdbcCommand myCommand = null;
        object obj = null;

        try
        {
            myCommand = new OdbcCommand(strSQL, myConnection);
            obj = myCommand.ExecuteScalar();
        }
        catch (Exception ex)
        {
            if (myConnection.State != ConnectionState.Open)
            {
                myConnection.Open();
                if (myCommand != null) myCommand.Dispose();

                try
                {
                    myCommand = new OdbcCommand(strSQL, myConnection);
                    obj = myCommand.ExecuteScalar();
                }
                catch (Exception ex2)
                {
                    if (Dict.IsRemote == true)
                    {
                        sendMail("error - לאחר ניסיון שני ExecuteStringQuery SQL s2s", strSQL, ex2);
                    }

                    throw ex2;
                }
            }
            else
            {
                if (Dict.IsRemote == true)
                {
                    sendMail("error ExecuteStringQuery SQL s2s", strSQL, ex);
                }

                throw ex;
            }
        }
        finally
        {
            if (myCommand != null) myCommand.Dispose();
        }

        return obj != null ? obj.ToString() : string.Empty;
    }

    public int ExecuteNoneQuery(string strSQL)
    {
        OdbcCommand myCommand = null;
        int i;
        try
        {
            myCommand = new OdbcCommand(strSQL, myConnection);
            i = myCommand.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            if (Dict.IsRemote == true)
            {
                sendMail("error ExecuteNoneQuery SQL s2s", strSQL, ex);
            }

            throw ex;
        }
        finally
        {
            if (myCommand != null) myCommand.Dispose();  
        }
        return i;
    }

    public int InsertGetLastID(string strSQL)
    {
        OdbcCommand myCommand = null;
        int LastID = 0;
        object objID = null;

        try
        {
            myCommand = new OdbcCommand(strSQL, myConnection);
            if (myCommand.ExecuteNonQuery() == 1)
            {
                myCommand = new OdbcCommand("SELECT LAST_INSERT_ID()", myConnection);
                objID = myCommand.ExecuteScalar();
                if (objID != null)
                {
                    LastID = int.Parse(objID.ToString());
                }
            }
        }
        catch (Exception ex)
        {
            if (Dict.IsRemote == true)
            {
                sendMail("error InsertGetLastID SQL s2s", strSQL, ex);
            }

            throw ex;
        }
        finally
        {
            if (myCommand != null) myCommand.Dispose();  
        }
        return LastID;
    }

    private void sendMail(string title, string sql, Exception ex)
    {
        string body = string.Empty +
            "SQL:\n\n" + sql + "\n\n" +
            "Exeption:\n\n" + ex.Message + "\n\n" +
            "Stack Trace:\n\n" + ex.StackTrace + "\n\n" +
            "Source:\n\n" + ex.Source + "\n\n";

        mailSend mailS = new mailSend("theMail", "mailTo", title, body);
    }
    #endregion
}
1
0
9/21/2012 12:41:26 PM

Popular Answer

When: 1. Development is carried out on a 32 bit operating system, convert to boolean function fails. 2. A 64-bit OS is used for implementation.

It functioned correctly after I changed the code for the Convert.ToBoolean method.

1
6/25/2012 9:49:29 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow