Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2009-02-09
8
Medium Priority
?
3,746 Views
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 )
        Values
        ( ?, ? , ? , ? , ?)";
 
public static void insertChatUser(User u)
    {
        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.1.30-community]Memory  
                 // allocation error"} EXCEPTION ALWAYS THROWN HERE 
        }
        finally
        {
            try
            {
                if (MyConn != null) MyConn.Close();
            }
            finally { }
        }
    }

Open in new window

0
Comment
Question by:baijajusav
  • 5
  • 3
8 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 23597129
the author in the following post says about data field too long
http://tomtech999.wordpress.com/2008/08/02/odbc-memory-allocation-error/

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
http://www.google.co.in/search?hl=en&q=MySql+Memory+allocation+error&btnG=Google+Search&meta=
0
 
LVL 3

Author Comment

by:baijajusav
ID: 23597182
ragi:

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.
0
 
LVL 3

Author Comment

by:baijajusav
ID: 23606197

Anyone have any ideas on this issue?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:baijajusav
ID: 23607977
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?
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 23612753
how are you passing the null value to the mysql stored procedure parameter
0
 
LVL 3

Author Comment

by:baijajusav
ID: 23612850

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.
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 2000 total points
ID: 23613005
Null values are handled using the DBNull class
DBNull.Value can be used to explicitly assign a nonexistent/null value to a database field
0
 
LVL 3

Author Closing Comment

by:baijajusav
ID: 31544873
Thanks!
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question