We help IT Professionals succeed at work.

Memory allocation error from MySql ODBC 5.1 driver in ASP .NET C# application on insert statement

Medium Priority
Last Modified: 2013-11-07
I have a ASP .NET application in C#. It's a simple web 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 website, 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:

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

I've tried switching everything over to the MyISam engine and increasing memory allocation where I could see it was used; however, I've got no idea why this is being caused.

I'm running on a Windows XP machine. My machine has 4 GB of memory (only 3 GB detected due to 32 bit).

I'm using MySql Administrator and am watching the connections and every time I open a connection, I see about 5 connections listed to the database. All of my methods close the connection too.

Anyone have any ideas? See code below
public static readonly String insertChatUser =
        @"insert into chatuser
        ( Username, Password, Firstname, Lastname,  Sex )
        ( ?, ? , ? , ? , ?)";
public static void insertChatUser(User u)
        OdbcConnection MyConn = DBConnection.getDBConnection();
        int result = -1;
            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.CommandText = mySqlQueries.insertChatUser;
            result = myCmd.ExecuteNonQuery();
        catch (Exception e)
                 //{"ERROR [HY001] [MySQL][ODBC 5.1 Driver][mysqld-5.1.30-community]Memory  
                 // allocation error"} EXCEPTION ALWAYS THROWN HERE 
                if (MyConn != null) MyConn.Close();
            finally { }

Open in new window

Watch Question

Anurag ThakurTechnical Manager

the author in the following post says about data field too long

have you installed the patches for ODBC drivers ... may be the problem has been fixed and its available in some patch as a lot of people have complained about the error



I did find that first article a bit after posting, but I confirmed that was not the issue. I am trying to insert nulls, but the columns where they go are nullable. The length of the data I'm inserting is shorter/smaller than the max size in the table.

The 2nd link wasn't very helpful. I have found several google entries describing this issue, but many are on linux machines and I'm yet to find a solution for a windows machine. On the mysql site, they do not have any patches that I can tell. That is where I got my odbc driver for mysql.

Thanks for chiming in, though. I'm pretty stumped so any lead will help.



Anyone have any ideas on this issue?


Okay I know where the issue is. It's when I'm inserting null data. Despite that working in MySql Query Bench, it is not working here. I can, however, insert blank data. The table does allow nulls for the fields that are submitting null.

Is there a MySql specific value that needs to be used for null when working with MySql 5.1 ODBC?
Anurag ThakurTechnical Manager

how are you passing the null value to the mysql stored procedure parameter



I have something like:

OdbcParameter firstName = new OdbcParameter("@FirstName", u.FirstName);

and u.FirstName happens to be null. When the insert is executed the out of memory exception is thrown. As a dirty fix, I have a function that checks the value for null and if it is null, it returns String.Empty instead as I'm not sure how to specifically insert a null.
Technical Manager
Null values are handled using the DBNull class
DBNull.Value can be used to explicitly assign a nonexistent/null value to a database field

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.