Solved

Questions About Multiple Transactions  Handling on SQL Server 2000

Posted on 2006-11-28
3
405 Views
Last Modified: 2010-04-04
Dear Sir,
  I have another problem need your support!
  I am trying to start two transactions at a time on SQL Server 2000!
  I declaired aTD1, aTD2 as TTransactionDesc, and set TransactionID with 1 and 2. (Please reffer to the code posted below!)
  When starting transactions, error occurs: A transaction is already active!
  Is there anything I do wrong!

Thanks for your help again!

  The Params of my TSQLConnection:
    DriverName=MSSQL
    HostName=192.168.9.7
    DataBase=tdsys
    User_Name=db1
    Password=*****
    BlobSize=-1
    ErrorResourceFile=
    LocaleCode=0000
    MSSQL TransIsolation=ReadCommited
    OS Authentication=False
    Prepare SQL=False
    Multiple Transaction=True
 
The source code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBXpress, StdCtrls, DB, SqlExpr;

type
  TForm1 = class(TForm)
    SQLConnection1: TSQLConnection;
    btnStart: TButton;
    btnEnd: TButton;
    lbStatus1: TLabel;
    lbStatus2: TLabel;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnEndClick(Sender: TObject);
    procedure btnStartClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    aTD1, aTD2: TTransactionDesc;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btnEndClick(Sender: TObject);
begin
  SQLConnection1.Rollback(aTD1);
  lbStatus1.Caption := 'End Transaction 1';
  SQLConnection1.Rollback(aTD2);
  lbStatus2.Caption := 'End Transaction 2';
end;

procedure TForm1.btnStartClick(Sender: TObject);
begin
  aTD1.TransactionID  := 1;
  aTD1.IsolationLevel := xilREADCOMMITTED;
  aTD2.TransactionID  := 2;
  aTD2.IsolationLevel := xilREADCOMMITTED;
  try
    SQLConnection1.StartTransaction(aTD1);
    lbStatus1.Caption := 'Start Transaction 1';
    SQLConnection1.StartTransaction(aTD2);
    lbStatus2.Caption := 'Start Transaction 2';
  except
    on E: Exception do ShowMessage(E.Message);
  end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  SQLConnection1.Connected := False;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  SQLConnection1.Connected := True;
end;

end.
0
Comment
Question by:daniel710624
3 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 500 total points
ID: 18034804
well, not sure if i am correct (because of not having sql2000-server), but as far as i know is that you can with one connection only one transaction (or even nested transactions), but no independend transactions.

my advice would be to use different connections
(which may cause in two sessions, which are independend)

just a guess

meikl ;-)
0
 
LVL 21

Expert Comment

by:ziolko
ID: 18035538
agree with kretzschmar, use two different connections.

ziolko
0
 

Author Comment

by:daniel710624
ID: 18035814
So, 'Multiple Transaction=True'  in TSQLConnection.Params is useless?
I found that TSQLConnection.MultipleTransactionsSupported is False after TSQLConnection.Active set to True, does that means SQL Server doesn't support multi-transaction?
If that's......I will be damn..... :*o*:
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now