PC Review


Reply
Thread Tools Rate Thread

Connections and Transactions

 
 
nashak@hotmail.com
Guest
Posts: n/a
 
      18th Jan 2005
We are logging errors into a table (yeah, I know what happens if db
access throws exceptions).

My parent method sets up a connection, opens connection and begins a
transaction. It then calls several methods and passes them the
connection and transaction objects. Now when an exception is thrown, I
create another method and have to now create a new connection to access
my DB table. I cannot use the original connection as in that case it
wants my sql commands to be bound to the parent transaction. After
logging the error, the exception passes to the try-catch block of
parent method that rollsback the transaction. However, I cannot create
a separate transaction in my LogError method even though I am using a
new connection object since the parent rollback also rollsback the
LogError write to the table. Any suggestion on how to go about fixing
this?

Thanks,

 
Reply With Quote
 
 
 
 
Sahil Malik
Guest
Posts: n/a
 
      18th Jan 2005
Can you show sample code of your try catch and your logerror routine?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> We are logging errors into a table (yeah, I know what happens if db
> access throws exceptions).
>
> My parent method sets up a connection, opens connection and begins a
> transaction. It then calls several methods and passes them the
> connection and transaction objects. Now when an exception is thrown, I
> create another method and have to now create a new connection to access
> my DB table. I cannot use the original connection as in that case it
> wants my sql commands to be bound to the parent transaction. After
> logging the error, the exception passes to the try-catch block of
> parent method that rollsback the transaction. However, I cannot create
> a separate transaction in my LogError method even though I am using a
> new connection object since the parent rollback also rollsback the
> LogError write to the table. Any suggestion on how to go about fixing
> this?
>
> Thanks,
>



 
Reply With Quote
 
nashak@hotmail.com
Guest
Posts: n/a
 
      18th Jan 2005
Hello,

Here is the code,


Public Sub Insert(ByVal drNewRow As DataRow, _
ByVal myconnection as sqlconnection, _
ByVal mytransaction as sqlTransaction)
......
daData.InsertCommand.Connection = myConnection
daData.InsertCommand.Transaction = myTransaction
daData.Update(dsData, myTable)

Catch ex As Exception

Dim newdbobject = New DBUtility
newdbobject.LogError(ex, myUserID)


Finally
.........

End Sub




Public Sub LogError(ByVal ex As Exception, _
ByVal userID As Long)
....
Try
myConnection1 = GetConnection()
myConnection1.Open()

cmdSelectData1.CommandText = "select * from Table"
cmdSelectData1.CommandType = CommandType.Text
cmdSelectData1.Connection = myConnection1

**Cannot create a new transaction and use BeginTransaction on this
connection

drRow1 = dsData1.Tables("ExceptionLog").NewRow
....
dsData1.Tables("ExceptionLog").Rows.Add(drRow1)
...
daData1.InsertCommand.Connection = myConnection1
**Cannot bind the insert command to local transaction. Parent method
rollback also rolls this insert back

daData1.Update(dsData1, "ESYSExceptionLog")

Catch exp As Exception
.....
Finally
myConnection1.Close()

End Try
End Sub


Please let me know if you need additional information.

 
Reply With Quote
 
Sahil Malik
Guest
Posts: n/a
 
      18th Jan 2005
Yes I need some more info

What is the code for "GetConnection"


- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> Here is the code,
>
>
> Public Sub Insert(ByVal drNewRow As DataRow, _
> ByVal myconnection as sqlconnection, _
> ByVal mytransaction as sqlTransaction)
> .....
> daData.InsertCommand.Connection = myConnection
> daData.InsertCommand.Transaction = myTransaction
> daData.Update(dsData, myTable)
>
> Catch ex As Exception
>
> Dim newdbobject = New DBUtility
> newdbobject.LogError(ex, myUserID)
>
>
> Finally
> ........
>
> End Sub
>
>
>
>
> Public Sub LogError(ByVal ex As Exception, _
> ByVal userID As Long)
> ...
> Try
> myConnection1 = GetConnection()
> myConnection1.Open()
>
> cmdSelectData1.CommandText = "select * from Table"
> cmdSelectData1.CommandType = CommandType.Text
> cmdSelectData1.Connection = myConnection1
>
> **Cannot create a new transaction and use BeginTransaction on this
> connection
>
> drRow1 = dsData1.Tables("ExceptionLog").NewRow
> ...
> dsData1.Tables("ExceptionLog").Rows.Add(drRow1)
> ..
> daData1.InsertCommand.Connection = myConnection1
> **Cannot bind the insert command to local transaction. Parent method
> rollback also rolls this insert back
>
> daData1.Update(dsData1, "ESYSExceptionLog")
>
> Catch exp As Exception
> ....
> Finally
> myConnection1.Close()
>
> End Try
> End Sub
>
>
> Please let me know if you need additional information.
>



 
Reply With Quote
 
nashak@hotmail.com
Guest
Posts: n/a
 
      18th Jan 2005
oops,

the things works

I was copying and pasting and realized that i didn't copy commit()
:-)

 
Reply With Quote
 
Sahil Malik
Guest
Posts: n/a
 
      18th Jan 2005
Okay .. that's the easiest help I've given out so far

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> oops,
>
> the things works
>
> I was copying and pasting and realized that i didn't copy commit()
> :-)
>



 
Reply With Quote
 
nashak@hotmail.com
Guest
Posts: n/a
 
      18th Jan 2005
LOL

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ADO Connections and transactions mscertified Microsoft Access Form Coding 0 17th Apr 2008 03:52 PM
Transactions across connections. Nerd Microsoft Dot NET 2 10th Feb 2006 04:51 PM
The order of closing transactions and connections? Frank Rizzo Microsoft C# .NET 1 21st May 2005 10:04 AM
Atomic transactions between .NET and COM (Interop) connections =?Utf-8?B?TW9udHNl?= Microsoft Dot NET 0 17th Feb 2005 03:27 PM
best practices for cleaning up connections, commands and transactions after errors occur? Andrew Microsoft ADO .NET 2 11th Nov 2003 09:31 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:46 AM.