Solved

Questions About Multiple Transactions  Handling on SQL Server 2000

Posted on 2006-11-28
3
402 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

759 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

17 Experts available now in Live!

Get 1:1 Help Now