Home All Groups Group Topic Archive Search About

SqlTransaction won't commit

Author
6 Jan 2006 6:27 AM
jack-b
Hi,

I'm running a process which takes records from an XML file and inserts
them one at a time into a database table. I'm using an SqlTransaction
to commit after each record is inserted but it doesn't seem to work. (I
need to commit each time because I sleep the thread after inserting 10
record for 1hour)

Code -

mySqlConnection = SqlConnection
mySqlConnection.ConnectionString = ConnectionString
mySqlConnection.Open()

mySqlTransaction = CreateJobDetails.mySqlConnection.BeginTransaction()

* retrieve record from XML file CODE ***

* push to DB ***

//assign parameter code etc etc

SqlHelper.ExecuteNonQuery( _
                            mySqlTransaction, _
                           CommandType.StoredProcedure, _
                            ProcName, _
                           InsertParameter)

            If InsertParameter(INDEX_RETURN_VALUE).Value <> 0 Then
                mySqlTransaction.Rollback()
                Throw New
StoredProcedureException(InsertParameter(INDEX_ERROR).Value)

            Else
                mySqlTransaction.Commit()
                mySqlTransaction.Dispose()
                mySqlConnection.Close()
            End If

***************************************
Do I have to state something in the stored procedure??

Any ideas??

Cheers,
Jack

Author
6 Jan 2006 4:19 PM
Jim Hughes
<jac***@humlog.com> wrote in message
Show quote
news:1136528842.460816.68580@o13g2000cwo.googlegroups.com...
> Hi,
>
> I'm running a process which takes records from an XML file and inserts
> them one at a time into a database table. I'm using an SqlTransaction
> to commit after each record is inserted but it doesn't seem to work. (I
> need to commit each time because I sleep the thread after inserting 10
> record for 1hour)
>
> Code -
>
> mySqlConnection = SqlConnection
> mySqlConnection.ConnectionString = ConnectionString
> mySqlConnection.Open()
>
> mySqlTransaction = CreateJobDetails.mySqlConnection.BeginTransaction()
>
> * retrieve record from XML file CODE ***
>
> * push to DB ***
>
> //assign parameter code etc etc
>
> SqlHelper.ExecuteNonQuery( _
>                            mySqlTransaction, _
>                           CommandType.StoredProcedure, _
>                            ProcName, _
>                           InsertParameter)
>
>            If InsertParameter(INDEX_RETURN_VALUE).Value <> 0 Then
>                mySqlTransaction.Rollback()
>                Throw New
> StoredProcedureException(InsertParameter(INDEX_ERROR).Value)
>
>            Else
>                mySqlTransaction.Commit()
>                mySqlTransaction.Dispose()
>                mySqlConnection.Close()
>            End If
>
> ***************************************
> Do I have to state something in the stored procedure??
>
> Any ideas??
>
> Cheers,
> Jack
>

Show the contents of the stored procedure as well as the parameters being
defined along with sample values and we can probably tell you.

AddThis Social Bookmark Button