#13 Exception on MySQLInsertCommand


Trying running a sample 'Sample_Insert-Update-Delete' i have got an exception 'PInvokeStackImbalance'

Messagge (in italian) is:
Una chiamata alla funzione PInvoke 'MySQLDriverCS!MySQLDriverCS.CPrototypes::mysql_real_escape_string' ha sbilanciato lo stack. Questo problema può verificarsi quando la firma PInvoke gestita non corrisponde alla firma di destinazione non gestita. Verificare che la convenzione di chiamata e i parametri della firma PInvoke corrispondano alla firma di destinazione non gestita.

Which translated in english sounds like: A call to PInvoke function 'MySQLDriverCS!MySQLDriverCS.CPrototypes::mysql_real_escape_string'
have imbalanced the stack.
has unbalanced the stack.
This is likely because the managed PInvoke signature does not match
the unmanaged target signature. Check that the calling convention and
parameters of the PInvoke signature match the target unmanaged signature.

I'm using Microsoft Visual Studio C# Express 2005 and Mysql version 5.
I have same issue with MySQLUpdateCommand.
This is another attempt width code written on new project:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MySQLDriverCS;

namespace TestMySqlDriveCS
public partial class Form1 : Form
public Form1()
MySQLConnection con;
con = new MySQLConnection(new MySQLConnectionString("server",

new MySQLInsertCommand(con, new object[,] { { "campo1", "Ciccio" }, { "Campo2", "Pluto" } }, "test");

string sql = "SELECT * FROM prova";

MySQLCommand cmd = new MySQLCommand(sql, con);

MySQLDataReader reader = cmd.ExecuteReaderEx();
string Testo = "";
while (reader.Read())
Testo += reader[0].ToString() + "\t" + reader[1].ToString() + "\t" + reader[2].ToString() + "\r\n";

textBox1.Text = Testo;
catch (Exception ee)
textBox1.Text = ee.ToString();

'Prova' is a table already exist in database 'test'


  • rmccullough

    rmccullough - 2007-07-10

    Logged In: YES
    Originator: NO

    I received the same exception and ended up doing my insert as a plain SQL statement rather than using the MySQLInsertCommand() function. If you need the exception in English, let me know and I will provide it.


  • Nobody/Anonymous

    Logged In: NO

    Same here:

    MySQLInsertCommand insertSomething = new MySQLInsertCommand ( this.sql_DBConnection, new Object[ , ] { { "user_name", "LastName" }, { "first_name", "FirstName" }, { "user_nick", "0[]" } }, "users" );

    leads to the PInvoke Imbalance error...

    and so it does not even contact the DB so it seems, so it can't be a DB issue... The DB workst fine otherwise (other commands)...

    I hope there is a solution...

  • rmccullough

    rmccullough - 2008-01-25

    Logged In: YES
    Originator: NO

    I tried the example in the initial post and can't reproduce.

    Can someone provide the "create table" statement and the C# code that is causing the issue and I will try to debug.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks