从MySQL ODBC 5.1驱动程序在INSERT语句C#应用程序内存分配错误语句、驱动程序、应用程序、分配

2023-09-03 17:24:47 作者:去坟场和僵尸聊天

我在C#.NET程序的Wndows应用程序。这是正在使用的MySQL 5.1数据库的社区版一个简单的Windows应用程序。我已经下载了MySQL的ODBC驱动程序,创建了一个DSN到我的数据库在我的本地机器。在我的应用程序,我可以执行GET类型的查询没有问题,但是当我执行给定插入语句(不,我试着做任何其他人),我得到以下错误:

{ERROR [HY001] [MySQL的] [ODBC 5.1驱动程序]的[mysqld-5.0.27-社区NT]内存分配错误}

我在Windows XP的计算机上运行。我的机器有1 GB的内存。 任何人有什么想法?请参阅下面

code

  OdbcConnection的myconn = DBConnection.getDBConnection();
    INT结果= -1;
    尝试
    {
        MyConn.Open();
        的OdbcCommand myCmd =新的OdbcCommand();
        myCmd.Connection =的myconn;
        myCmd.CommandType = CommandType.Text;
        OdbcParameter的userName =新OdbcParameter(@用户名,u.UserName);
        OdbcParameter密码=新OdbcParameter(@密码,u.Password);
        OdbcParameter的firstName =新OdbcParameter(@名字,u.FirstName);
        OdbcParameter姓氏=新OdbcParameter(@名字,u.LastName);
        OdbcParameter性=新OdbcParameter(@性,u.Sex);
        myCmd.Parameters.Add(用户名);
        myCmd.Parameters.Add(密码);
        myCmd.Parameters.Add(名字);
        myCmd.Parameters.Add(姓氏);
        myCmd.Parameters.Add(性);
        myCmd.CommandText = mySqlQueries.insertChatUser;
        结果= myCmd.ExecuteNonQuery();
    }
    赶上(例外五)
    {
             // {ERROR [HY001] [MySQL的] [ODBC 5.1驱动程序]的[mysqld-5.0.27-社区NT]内存
             //分配错误}例外总是抛出此位置
    }
    最后
    {
        尝试
        {
            如果(!的myconn = NULL)MyConn.Close();
        }
        最后 { }
    }
 

解决方案

这是因为有些字段接受空,我公司已通过他们的,他们应该传递空的DBNull.Value。对于所有允许空应检查空,如果发现无效,应该的DBNull.Value传递的字段。

I have a .NET Wndows application in C#. It's a simple Windows application that is using the MySql 5.1 database community edition. I've downloaded the MySql ODBC driver and have created a dsn to my database on my local machine. On my application, I can perform get type queries without problems, but when I execute a given insert statement (not that I've tried doing any others), I get the following error:

采用MYSQL odbc 3.51访问数据库返回值缺失

{"ERROR [HY001] [MySQL][ODBC 5.1 Driver][mysqld-5.0.27-community-nt]Memory allocation error"}

I'm running on a Windows XP machine. My machine has 1 GB of memory. Anyone have any ideas? See code below

OdbcConnection MyConn = DBConnection.getDBConnection();
    int result = -1;
    try
    {
        MyConn.Open();
        OdbcCommand myCmd = new OdbcCommand();
        myCmd.Connection = MyConn;
        myCmd.CommandType = CommandType.Text;
        OdbcParameter userName = new OdbcParameter("@UserName", u.UserName);
        OdbcParameter password = new OdbcParameter("@Password", u.Password);
        OdbcParameter firstName = new OdbcParameter("@FirstName", u.FirstName);
        OdbcParameter LastName = new OdbcParameter("@LastName", u.LastName);
        OdbcParameter sex = new OdbcParameter("@sex", u.Sex);
        myCmd.Parameters.Add(userName);
        myCmd.Parameters.Add(password);
        myCmd.Parameters.Add(firstName);
        myCmd.Parameters.Add(LastName);
        myCmd.Parameters.Add(sex);
        myCmd.CommandText = mySqlQueries.insertChatUser;
        result = myCmd.ExecuteNonQuery();
    }
    catch (Exception e)
    {
             //{"ERROR [HY001] [MySQL][ODBC 5.1 Driver][mysqld-5.0.27-community-nt]Memory  
             // allocation error"} EXCEPTION ALWAYS THROWN HERE 
    }
    finally
    {
        try
        {
            if (MyConn != null) MyConn.Close();
        }
        finally { }
    }

解决方案

It was because some fields accept null, I had passed them as null where they should be passed as DBNull.Value. For all the fields which allow null should be checked for null and if found null, DBNull.Value should be passed.