开发者

Arithmetic operation resulted in an overflow

After updating my website on ii7 on window server 2008 from framework 3.5 to work with framework 4 i got my c# base database class stop working copmlitly with this error: "Arithmetic operation resulted in an overflow". I am working with mysql server from different server.

I did not find any solution on this so i had very sadness to role bakce to framework 3.5

here is some of my logs for this error in the event viewr on my server:


Process information: Process ID: 3680 Process name: w3wp.exe Account name: NT AUTHORITY\NETWORK SERVICE

Exception information: Exception type: OverflowException Exception message: Arithmetic operation resulted in an overflow. at DataAccess.ExecuteStringQuery(String strSQL) in d:\webSites\s2s\App_Code\DB\DataAccess.cs:line 214 at DataSelect.generalString(String rowName, String tableName, String idName, String ID) in d:\webSites\s2s\App_Code\DB\DataSelect.cs:line 48 at camsBaseShowWeb.OnPreInit(EventArgs e) in d:\webSites\s2s\App_Code\Bases\camsBaseShowWeb.cs:line 134 at System.Web.UI.Page.PerformPreInit()

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

big thanks for any halp


i got this error - no matter wich function i try to call from this code

here 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 DataAcc开发者_JAVA百科ess()
    {
        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
}


I was getting this too since the upgrade to .Net 4.0

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() at Server.Engines.MyRunUO.DatabaseCommandQueue.Thread_Start() in d:\RunUO\Sec ondAge\Scripts\Engines\MyRunUO\DatabaseCommandQueue.cs:line 117

OdbcConnection version is System.Data.dll, v4.0.30319 Using "{MySQL ODBC 5.1 Driver}" (actually 5.01.06.00) against MySQL 5.1.40-community via TCP/IP on localhost.

The query was any variation of: SELECT COUNT(*) FROM myrunuo_timestamps WHERE time_type='chardb'

The (apparently) offending lines:

command.CommandText = string.Format("SELECT COUNT(*) FROM myrunuo_timestamps WHERE time_type='{0}'", m_timeStampName); // Line 116

object result = command.ExecuteScalar(); // Line 117

This occurred with an x64 compile only, i.e. using the x64 mySQL driver.

This was fixed by upgrading from mySQL ODBC driver 5.01.06.00 to 5.01.08.00


conver to boolean function does not work when 1. Development is done on 32 bit OS 2. Implementation is done on 64 bit OS

When I altered the code for Convert.ToBoolean function, It worked normally.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜