Still speaking about COM+ vs SQL Server transactions, how problematic can be
using a class like the following (some kind of a decorator for a SQLTrans
object)? It's probably full of minor & MAJOR bugs but that's not the point,
the point is how usable can be something like this? I'm specially sensitive
to security drawbacks also (there are certainly some).

  Public Class SharedTransaction
        Private _Doomed As Boolean
        Private _RootObjectHash As Integer
        Private SQLTx As SqlClient.SqlTransaction
        Private Con As SqlClient.SqlConnection

        Public Sub New(ByVal ConnectionString As String, ByVal Root As
Object)
            'Store some kind of Id for the root object of the transaction
            _RootObjectHash = Root.GetHashCode 'possibly unsafe check,
testing

            'Open proper connection & begin transaction
            Con = New SqlClient.SqlConnection(ConnectionString)
            Con.Open()

            SQLTx = Con.BeginTransaction

            'By default
            _Doomed = False

        End Sub

        Public Sub Join(ByVal Com As SqlClient.SqlCommand)
            'Makes the command execute inside our Transaction

            Com.Transaction = SQLTx
            Com.Connection = Con
        End Sub


        Public Function Commit(ByVal Caller As Object)
            'Some kind of a COM+ SetComplete
            If Caller.GetHashCode = _RootObjectHash Then
                'Final
                If _Doomed Then
                    'Someone has voted for rollback
                    SQLTx.Rollback()
                Else
                    'Everything went fine
                    SQLTx.Commit()
                End If

                Con.Close()
                Con.Dispose()
                SQLTx.Dispose()

            End If


        End Function

        Public Function Rollback(ByVal Caller As Object)
            'Some kind of a COM+ SetAbort
            If Caller.GetHashCode = _RootObjectHash Then

                'Final
                SQLTx.Rollback()

                Con.Close()
                Con.Dispose()
                SQLTx.Dispose()

            Else
                _Doomed = True
            End If

        End Function

    End Class


My thoughts:

Clients (web, win32,etc)  make calls to tx business objects without passing
any kind of a SharedT instance (optional value with a default of nothing),
so it's still stateless enough to be used remotely with nlbs or web
services. Tx business objects will create a new SharedT if none is passed to
them, they can choose wether to pass a SharedT  when locally calling other
tx business objects methods.

We span the transaction only when needed (I think it will be needed most of
the times). We don't use COM+/DTC serializable transactions but ADO.NET SQL
transactions (so we are able to define the appropriate isolation level).

I doubt that this can be a valid and stable solution (altough it's working
fairly well), but anyway, I was just testing possible scenarios.



RQ

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to