Hi,
   you can always check if the DataAdapter already has the commands, and if it does attribute the connection and transaction to them.

ex if (da1.SelectCommand != null)
     {
            da1.SelectCommand.Connection=cn;
            sa1.SelectCommand.Transaction = tr;
     }
     if (da1.UpdateCommand != null)
     {
            da1.UpdateCommand.Connection=cn;
            sa1.UpdateCommand.Transaction = tr;
     }
    if (da1.DeleteCommand != null)
     {
            da1.DeleteCommand.Connection=cn;
            sa1.DeleteCommand.Transaction = tr;
     }
    if (da1.InsertCommand != null)
     {
            da1.InsertCommand.Connection=cn;
            sa1.InsertCommand.Transaction = tr;
     }

Paulo Gomes

Em 10-10-2011 15:33, Francesco Giossi escreveu:
Hi Paulo,
yes, it works!

I added this code as 1st lines in the try...catch
--------------------------------------
da1 = new FbDataAdapter("SELECT * FROM MyTable WHERE PK = 1", cn);
da1.TableMappings.Add("Table", "MyTable");
FbCommandBuilder cbTest = new FbCommandBuilder(da1);
--------------------------------------

The only matter, now, is around performances. I guess it won't be that good.
I see if can be acceptable.
So far, your idea fixed my problem

thank you very much

F


2011/10/10 Paulo Gomes <paulo_...@sapo.pt>
Hi,
  Try recreating the adapter, it should work as first time.

Paulo Gomes

Em 10-10-2011 11:16, Francesco Giossi escreveu:
Hi,
thanks for your answer.
Well, I tried to remove the transaction, commenting the code. Well, the behaviour is exactly the same, with the same error message: invalid transaction handle(expecting explicit transaction start).
What kind of transaction is it referring to if there is no transaction open?
I'm so lost

2011/10/10 Paulo Gomes <paulo_...@sapo.pt>
Hi,
  I think it has to do with the fact that the data adapter you are using hasn't the same scope as the connection, you sould have in mind tha the DataAdapter has 4 commands and the ones who perform the changes to the dataset aren't in the scope of the current transaction. it goes well in the first becaus when the commands are created they get the current transaction assigned.

Hope this helps...

Paulo Gomes
 

Em 10-10-2011 08:48, Francesco Giossi escreveu:
Hi,
I'm working with Visual studio 2008, C#, firebird 2.1 and .net provider 2.6.5.0.

I have a problem with FbDataAdapter. Using the dataadapter to update the records in my datatable, I get an error: "invalid transaction handle".
The problem never shows up when I use the command for the 1st time.
From the 2nd time and next, I ALWAYS receive that error.

To keep it simple, here is the code I'm struggling with
(I have a very simple sample project if needed)
What am I doing wrong? This works perfectly with Sql Server express or server 2008.

----------------------------------------------------------

FbConnection cn = new FbConnection(ConnectionString);
            
cn.Open();
FbTransaction tr = cn.BeginTransaction(IsolationLevel.ReadCommitted);

try
{
    da1.SelectCommand.Connection = cn;
    da1.SelectCommand.Transaction = tr;
    
    da1.Update(ds);

    tr.Commit();
    MessageBox.Show("OK!","", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
    tr.Rollback();
    MessageBox.Show("ERROR\r\n" + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
cn.Close();
tr.Dispose();
----------------------------------------------------------

where...
da1 is a FbDataAdapter
ds is my dataset containing only one datatable

the stack trace is:
   in FirebirdSql.Data.FirebirdClient.FbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) in C:\Users\Jiri\Desktop\NETProvider\source\FirebirdSql\Data\FirebirdClient\FbDataAdapter.cs:riga 455
   in System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
   in System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
   in System.Data.Common.DbDataAdapter.Update(DataSet dataSet)
   in DataSetFireBird.Form1.button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Joss\Documenti\Comelit\_Codice\DataSetFireBird\DataSetFireBird\Form1.cs:riga 63


I even tried the workaround and the solution proposed here
but, when it's about the workaround, it doesn't work.
On the other hand, I don't get how to apply the fix proposed by Jiri.

The last but not least, the error NEVER shows up when using the server mode, but is ALWAYS shown when using the embedded version. The difference is, obviously, in the connection string to the database.

here are the two connection strings
SERVER:        private String ConnectionString = @"Server=localhost;User=SYSDBA;Password=masterkey;Database=C:\Documents and Settings\Joss\Documenti\Test\db\test.FDB";
EMBEDDED:        private String ConnectionString = @"User=SYSDBA;Password=masterkey;Database=C:\Documents and Settings\Joss\Documenti\Test\db\test.FDB;server type=Embedded;charset=UTF8;";


In my environment is supposed to use the embedded version (it's a redistributable application).

Thanks in advance


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1


_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider




------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1


_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider




------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1


_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

Reply via email to