Geekpedia Programming Tutorials






Does ServiceDomain.Enter Create DTC?

On Thursday, August 28th 2008 at 01:06 AM
By mike
I have a scenario where I need to get the ITransaction* within an
extended stored proc within SQL 2005. I've written C++/CLI managed
data access routine that are called by native code. these wrappers
call sprocs that in turn call the xproc that tries to get the
ITransaction*. If I wrap my sprocs with "BEGIN DISTRIBUTED
TRANSACTION" and don't provided for Tx support in my data access
routines, this will work. However, I'm trying to use SWC so I can
eliminate the declaration in my sprocs for the dtc. below is part of
my code:

At the top of one of my functions, I do this:


System::Threading::Monitor::Enter( command );

ServiceConfig^ config = gcnew ServiceConfig();
config->Transaction = TransactionOption::RequiresNew;

command->Connection =
gcnew ::System::Data::SqlClient::SqlConnection( m_ConnStr );

when I'm ready to execute the sproc, I do this:
try
{
ServiceDomain::Enter( config );

returnValue = command->ExecuteNonQuery();

ContextUtil::SetComplete();
}
catch( ... )
{
ContextUtil::SetAbort();
}
finally
{
TransactionStatus^ status = ServiceDomain::Leave();
command->Connection->Close();
}

the status returned from Leave is Committed. However, when I debug my
xproc, the call to the function to return the dtc ITransaction*
fails.

My question is this, does what I've done create a DTC or is this
creating a Sql transaction? If DTC, why can I not see it within the
path of execution?

Any help/ideas/insight will be greatly appreciated.

Mike

Re: Does ServiceDomain.Enter create DTC?

by mike on Thursday, August 28th 2008 at 11:04 AM
On Aug 27, 10:06=A0pm, mike <mikebi...@hotmail.com> wrote:
> I have a scenario where I need to get the ITransaction* within an
> extended stored proc within SQL 2005. =A0I've written C++/CLI managed
> data access routine that are called by native code. =A0these wrappers
> call sprocs that in turn call the xproc that tries to get the
> ITransaction*. =A0If I wrap my sprocs with "BEGIN DISTRIBUTED
> TRANSACTION" and don't provided for Tx support in my data access
> routines, this will work. =A0However, I'm trying to use SWC so I can
> eliminate the declaration in my sprocs for the dtc. below is part of
> my code:
>
> At the top of one of my functions, I do this:
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 System::Threading::Monitor::Enter( comman=
d );
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ServiceConfig^ config =3D gcnew ServiceCo=
nfig();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 config->Transaction =3D TransactionOption=
::RequiresNew;
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 command->Connection =3D
> gcnew ::System::Data::SqlClient::SqlConnection( m_ConnStr );
>
> when I'm ready to execute the sproc, I do this:
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 try
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ServiceDomain::Enter( con=
fig );
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 returnValue =3D command->=
ExecuteNonQuery();
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ContextUtil::SetComplete(=
);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 catch( ... )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ContextUtil::SetAbort();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 finally
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TransactionStatus^ status=
=3D ServiceDomain::Leave();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 command->Connection->Clos=
e();
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
>
> the status returned from Leave is Committed. =A0However, when I debug my
> xproc, the call to the function to return the dtc ITransaction*
> fails.
>
> My question is this, does what I've done create a DTC or is this
> creating a Sql transaction? =A0If DTC, why can I not see it within the
> path of execution?
>
> Any help/ideas/insight will be greatly appreciated.
>
> Mike

I figured it out. I needed to enlist the connection into the dtc...
Latest Tech Bargains

Advertisement

Free Magazine Subscriptions

Today's Pictures

Today's Video

Other Resources

Latest Download

Latest Icons