Home All Groups Group Topic Archive Search About

Filling from inside a transaction?

Author
10 Jul 2006 7:06 PM
Mike King
How can one fill a DataSet or DataTable from inside a transaction?  I'm
receiving an exception when the following Fill method is executed.

DataTable dt = new DataTable();
OracleDataAdapter da = new OracleDataAdapter("SELECT * FROM dual", conn);
da.Fill(dt);

### EXCEPTION ###
Execute requires the Command object to have a Transaction object when the
Connection object assigned to the Command is in a pending local transaction.
The Transaction property of the Command has not been initialized.

Author
10 Jul 2006 7:38 PM
Mike King
Show quote
"Mike King" <emai***@excite.com> wrote in message
news:eaZanQFpGHA.1548@TK2MSFTNGP04.phx.gbl...
> How can one fill a DataSet or DataTable from inside a transaction?  I'm
> receiving an exception when the following Fill method is executed.
>
> DataTable dt = new DataTable();
> OracleDataAdapter da = new OracleDataAdapter("SELECT * FROM dual", conn);
> da.Fill(dt);
>
> ### EXCEPTION ###
> Execute requires the Command object to have a Transaction object when the
> Connection object assigned to the Command is in a pending local
> transaction. The Transaction property of the Command has not been
> initialized.

I solved my problem by using a DataReader.

cmd = new OracleCommand();
cmd.CommandText = "select * from dual";
cmd.Connection = conn;
cmd.Transaction = trans;

IDataReader rdr = cmd.ExecuteReader();

while (rdr.Read())
{
//... do the magic
rdr.GetString(0);
}
Author
10 Jul 2006 7:42 PM
Sahil Malik [MVP C#]
Just set the OracleTransaction you have to the
OracleDataAdapter.SelectCommand.Transaction property and the below should
work fine.

- Sahil Malik [MVP]
http://blah.winsmarts.com




Show quote
"Mike King" <emai***@excite.com> wrote in message
news:eaZanQFpGHA.1548@TK2MSFTNGP04.phx.gbl...
> How can one fill a DataSet or DataTable from inside a transaction?  I'm
> receiving an exception when the following Fill method is executed.
>
> DataTable dt = new DataTable();
> OracleDataAdapter da = new OracleDataAdapter("SELECT * FROM dual", conn);
> da.Fill(dt);
>
> ### EXCEPTION ###
> Execute requires the Command object to have a Transaction object when the
> Connection object assigned to the Command is in a pending local
> transaction. The Transaction property of the Command has not been
> initialized.
>
>
>
Author
10 Jul 2006 8:00 PM
Mike King
"Sahil Malik [MVP C#]" <contactmethrumyblog@nospam.com> wrote in message
news:ObbLEkFpGHA.5104@TK2MSFTNGP04.phx.gbl...
> Just set the OracleTransaction you have to the
> OracleDataAdapter.SelectCommand.Transaction property and the below should
> work fine.
>
> - Sahil Malik [MVP]
> http://blah.winsmarts.com


Thanks!

AddThis Social Bookmark Button