算术运算导致溢出

时间:2010-11-01 10:12:50

标签: asp.net mysql entity-framework

在窗口服务器2008上的ii7上从框架3.5更新我的网站后,使用框架4 我得到了我的c#基础数据库类停止工作copmlitly与此错误:“算术运算导致溢出”。 我正在使用来自不同服务器的mysql服务器。

我没有找到任何解决方案,所以我对角色bakce非常悲伤到框架3.5

以下是我服务器上事件查看器中此错误的一些日志:


流程信息:     进程ID:3680     进程名称:w3wp.exe     帐户名称:NT AUTHORITY \ NETWORK SERVICE

异常信息:     异常类型:OverflowException     异常消息:算术运算导致溢出。    位于d:\ webSites \ s2s \ App_Code \ DB \ DataAccess.cs中的DataAccess.ExecuteStringQuery(String strSQL):第214行    位于d:\ webSites \ s2s \ App_Code \ DB \ DataSelect.cs中的DataSelect.generalString(String rowName,String tableName,String idName,String ID):第48行    at camsBaseShowWeb.OnPreInit(EventArgs e)在d:\ webSites \ s2s \ App_Code \ Bases \ camsBaseShowWeb.cs:第134行    在System.Web.UI.Page.PerformPreInit()

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

非常感谢任何halp


我收到了这个错误 - 无论我试图通过此代码调用哪个函数

这是我的代码:

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
}

2 个答案:

答案 0 :(得分:1)

自升级到.Net 4.0以来,我也得到了这个。

  

System.OverflowException:算术运算导致溢出。      在System.Data.Odbc.OdbcDataReader.GetSqlType(Int32 i)      在System.Data.Odbc.OdbcDataReader.GetValue(Int32 i)      在System.Data.Odbc.OdbcCommand.ExecuteScalar()      在d:\ RunUO \ Sec中的Server.Engines.MyRunUO.DatabaseCommandQueue.Thread_Start()   ondAge \ Scripts \ Engines \ MyRunUO \ DatabaseCommandQueue.cs:第117行

OdbcConnection版本是System.Data.dll,v4.0.30319 在localhost上通过TCP / IP使用“{MySQL ODBC 5.1 Driver}”(实际上是5.01.06.00)对MySQL 5.1.40-community。

查询是以下任何变体: SELECT COUNT(*)FROM myrunuo_timestamps WHERE time_type ='chardb'

(显然)违规行:

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

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

这只发生在x64编译中,即使用x64 mySQL驱动程序。

通过从mySQL ODBC驱动程序5.01.06.00升级到5.01.08.00

来解决此问题

答案 1 :(得分:1)

转换为布尔函数时不起作用 1.开发在32位操作系统上完成 2.实现在64位OS上完成

当我更改Convert.ToBoolean函数的代码时,它正常工作。