Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to insert 1000000 records to firebird with this code but i got error "undeffined message number".


C#
static void FirebirdInsert(int iter)
{
    using (FbTransaction trans = _fbcon.BeginTransaction())
    {

        using (FbCommand cmd = _fbcon.CreateCommand())
        {

           byte[] value = File.ReadAllBytes(@"nnn.jpg");
           cmd.Transaction = trans;
           cmd.CommandText = "execute block as declare"
                              +" i int = 0;"
                              +"begin"
                              +"while (i <"+ iter +") do"
                              +"begin"
                              +"insert into t2"
                              +"(MBR, FIR, IME, PRZ, VRE, B) values"
                              +"(null,6156830,'Goran','Vidak',current_timestamp,@b);"
                              +"i = i + 1;"
                              +"end"
                              +"end";

            cmd.Parameters.Add("b", FbDbType.Binary, value.Length).Value = value;

            cmd.ExecuteNonQuery();
            trans.Commit();
        }
        _fbcon.Close();
    }
}


I dont know if maybe i cannot use parameter (which is blob type) in execute block this way. I also try instead of execute block (also in transaction) and that worked but very slow, about 8
inserts/sec. Command as execute block for simplier excample worked about 100x faster for me than
transaction with for loop. Any suggestion? Thanks in advance.

C#
FbCommand cmd = new FbCommand("insert into t2"
                                  +"(MBR, FIR, IME, PRZ, VRE, B) values"
                                  +"(null,6156830,'Goran','Vidak',current_timestamp,@b);",_fbcon );
                    for (int i = 0; i < iter; i++)
                    {
                        cmd.Parameters.Add("b", FbDbType.Binary,value.Length).Value = value;
                        
                        cmd.ExecuteNonQuery();
                    }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900