Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
MS-SQL : connection is in use by another statement Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
25-Aug-02
Category
DB-General
Language
Delphi 2.x
Views
64
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas 

MS-SQL : connection is in use by another statement

Answer:

When porting a larger database application (130k LOC) that worked fine with Oracle 
and InterBase to MS-SQL (6.5), I frequently got the error message 'connection is in 
use by another statement'.

At first, creating a new TDatabase for each TTable/ TQuery seemed to be necessary.

Then I found what was 'wrong' (not really wrong.. :-)

To speed up some of my queries, I had set the property Unidirectional to true. 
Delphi creates for such queries only one cursor (versus two for bidirectional 
queries or TTables). After removing the assignments of Unidirectional := true the 
error message disappeared and everything worked fine.

The following code resulted in the exception 'connection is in use by another 
statement':
1   
2   // dataBaseNameS : string  is the name of the alias (MS-SQL 6.5)
3   begin
4     Query1 := TQuery.Create(Application);
5     with Query1 do
6     begin
7       DatabaseName := dataBaseNameS;
8       SQL.Text := 'SELECT * FROM ABLESTOP';
9       // the exception disappears if the following is removed
10      Unidirectional := True;
11      Open;
12    end;
13    ShowMessage('ok')
14  
15    Table1 := TTable.Create(Self);
16    with Table1 do
17    begin
18      DatabaseName := dataBaseNameS;
19      TableName := 'COMPONENT_PLAN';
20      UpdateMode := upWhereKeyOnly;
21      Open
22    end;
23  
24    Table1.Insert;
25    Table1.FieldByName('PARTNO').AsString := IntToStr(GetTickCount);
26    Table1.FieldByName('ID').AsString := 'WWxx';
27    Table1.FieldByName('VERSION').AsInteger := 1;
28    // the exception will occurr in the next statement:
29    //     "Connection is in use by another statement"
30    Table1.Post;
31  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC