Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use TransactionScope with OleDB in .NET?

811368Nov 8 2010 — edited Nov 15 2010
We are developing a .NET application using an oracle database and OleDB.
However, whenever we try to execute a command within a "TransactionScope" we run into an exception when opening the connection.

I have included a simple sample to demonstrate this.
This same code runs successfully if we comment out the TransactionScope lines.


Does anyone else have experience with this?
Any help is appreciated.

Thanks,

-Joel


connectionString = "Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=theHost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=theServiceName)));User Id=theID;Password=thePassword;";

query = "update test_table set test_column = 8 where test_id = 4";


private static int OleTest(string connectionString, string query)
{
int results;
using (TransactionScope scope = new TransactionScope())
{
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
using (OleDbCommand cmd = conn.CreateCommand())
{
cmd.CommandText = query;
conn.Open();//<-- throws the exception here
results = cmd.ExecuteNonQuery();
conn.Close();
}
}
scope.Complete();
}
return results;
}

Exception thrown:

System.ArgumentException

Value does not fall within the expected range.

at System.Data.Common.NativeMethods.ITransactionJoin.JoinTransaction(Object punkTransactionCoord, Int32 isoLevel, Int32 isoFlags, IntPtr pOtherOptions)
at System.Data.OleDb.OleDbConnectionInternal.EnlistTransactionInternal(Transaction transaction, Boolean forcedAutomatic)
at System.Data.OleDb.OleDbConnection.Open()
at OleDBTransactionScope.Program.OleTest(String connectionString, String query) in C:\SvnRepository\OleDBTransactionScope\OleDBTransactionScope\Program.cs:line 35
at OleDBTransactionScope.Program.Main(String[] args) in C:\SvnRepository\OleDBTransactionScope\OleDBTransactionScope\Program.cs:line 16
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 13 2010
Added on Nov 8 2010
1 comment
1,443 views