RE: Transaction Query

From: Tal Geva (Geva_at_discussions.microsoft.com)
Date: 06/29/04


Date: Tue, 29 Jun 2004 09:11:50 -0700

I understand you want to write a vb/c# program and control the transacction.
so, here is some code in vb.net:
' declare the command - I used a stored proc but any insert\delete\update sql statement will do
Dim YourCmd As New System.Data.SqlClient.SqlCommand(stord_proc_name,yourdbConnection)
YourCmd .CommandType = CommandType.StoredProcedure
'declare the transaction object
Dim trans As System.Data.SqlClient.SqlTransaction
'fill parameters into the stored proc params
'set the transaction as a Specific db connection transaction
trans = yourdbConnection.BeginTransaction
YourCmd.Transaction = trans
' from here you can run the sql statement as many times as you need. when you want to commit:
trans.commit()
'or
trans.Rollback()

'and if you want to have another cycle, you need to repeat on those statements:
trans = yourdbConnection.BeginTransaction
YourCmd.Transaction = trans

Hope that helped
Tal

"Jude_44" wrote:

> Hi There
>
> I have been trying to establish how Transactions work from a .NET component.
> Basically, I have an operation I want to work in a transactional manner, but I would like to control this from within a function.
> How does Enterprise Services relate to COM+? Can I use Enterprise Services on a system without it having COM+ set up and my component installed there?
>
> So basically I need to something like the following within a method:
>
> Start a Transaction
> Perform a number of ADO calls to my SQL Server DB, with numerous connection objects and many changes to DB records. If theres a problem I want it to roll back all DB changes.
> End Transaction, and Commit if successful.
>
> Do I need to put it all within a single StoredProcedure in order to get Transactional support, or is there a way I can do it from VB.NET using EnterpriseServices, without having to rely on COM+ being installed and component registered within same COM+?
>
> Thanks for all your help!!
>
> Regards
> David Crone



Relevant Pages

  • Re: Backups and Transaction Log file size
    ... It sounds like a classic case of a long running open transaction. ... Find the client and either commit or roll it back. ... If you know it is a garbage connection you can kill the SPID and it will roll back any changes that the SPID may have open and allow you to backup and truncate properly. ... Once the committed trans have been ...
    (microsoft.public.sqlserver.setup)
  • Re: Typed Dataset and transactions in ADO.NET 2.0
    ... Maybe this style...just across a couple of commands ... SqlTransaction trans; ... bReturnLog = ErrorLog.ErrorRoutine; ... I have a general question about typed datased and transaction. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Trouble with query
    ... -- creates a temporary table for containing some transaction records ... from #trans as tr inner join ... #transtype ty on tr.idtranstype = ty.idtranstype ...
    (microsoft.public.sqlserver.programming)
  • Re: Linked Server & XACT_ABORT
    ... EXEC sp_configure 'remote proc trans', ... "Unable to start a nested transaction for OLE DB provider 'IBMDADB2'. ... > Wayne Snyder, MCDBA, SQL Server MVP ... >> at the linked server level? ...
    (microsoft.public.sqlserver.server)
  • Transaction error
    ... i have a windows form application and i want to use an insert command within a transaction so i satrt the transaction: (Conn is my connection object) ... System.Data.OleDb.OleDbTransaction Trans; ...
    (microsoft.public.dotnet.languages.csharp)