算术溢出-Int32 MySQL到C#

本文关键字:MySQL -Int32 溢出 | 更新日期: 2023-09-27 17:50:54

体系结构:

-一个运行windows 2008和IIS 7的web服务器,承载在.NET框架4.0中开发的.NET web应用程序。在同一台服务器上,我有驱动程序MySQL ODBC 3.5.1驱动程序

-在Unix 上运行的MySQL数据库服务器

问题:

    public static List<Entity.Document> list(int companyId, int folderId, int userId)
    {
        //Initialise the results
        List<Entity.Document> results = new List<Entity.Document>();
        try
        {
            using (OdbcConnection connection = new OdbcConnection(ConfigurationManager.ConnectionStrings["MySQL"].ConnectionString))
            {
                connection.Open();
                using (OdbcCommand command = new OdbcCommand(string.Concat("SELECT id, name, parentfolderid, gid, companyid, is_deleted FROM tbl_document where parentfolderid = '" + folderId + "' and companyid = '", companyId, "' ORDER BY name"), connection))
                using (OdbcDataReader dr = command.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        Entity.Document item = new Entity.Document();
                        
                        item.Id = int.Parse(dr["id"].ToString());
                        item.Name = dr["name"].ToString();
                        item.gId = Guid.Parse(dr["gid"].ToString());
                        if (string.IsNullOrEmpty(dr["parentfolderid"].ToString()))
                            item.FolderId = 0;
                        else
                            item.FolderId = int.Parse(dr["parentfolderid"].ToString());
                        if (dr["is_deleted"].ToString() == "1")
                            item.IsDeleted = true;
                        else
                            item.IsDeleted = false;
                        results.Add(item);
                    }
                    dr.Close();
                }
                connection.Close();
            }
        }

当代码行item.Id=int.Parse(dr["Id"].ToString((时,我出现以下错误:

5/26/2015 (9:29 AM) - Method: System.Collections.Generic.List`1[Entity.Folder] listFolders(Int32, Int32, Int32)
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 DA.Folder.listFolders(Int32 parentFolderID, Int32 companyId, Int32 userId) in D:'Websites'AMS'AMS1.2'DA'Folder.cs:line 39

注意,我还检查了从dr["id"]返回的值的类型,如下所示:名称:Int32

全名:System.Int32

我也试过System.Convert.ToInt32

您可以在下面找到目标表的描述:

mysql> describe tbl_folder;

+----------------+------------+------+-----+---------+----------------+
| Field          | Type       | Null | Key | Default | Extra          |
+----------------+------------+------+-----+---------+----------------+
| id             | int(11)    | NO   | PRI | NULL    | auto_increment |
| name           | longtext   | NO   |     | NULL    |                |
| parentfolderid | int(11)    | YES  |     | NULL    |                |
| companyid      | int(11)    | NO   |     | NULL    |                |
| is_deleted     | tinyint(4) | NO   |     | NULL    |                |
+----------------+------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
mysql>

任何帮助都将不胜感激。

算术溢出-Int32 MySQL到C#

我设法解决了这个问题。在64位体系结构上的32位操作系统上部署一个开发的应用程序是个问题。我在一个64位的env上编译并部署了相同的源代码。现在它可以工作了!无论如何,感谢您的帮助:(