user5532532
user5532532

Reputation:

Connection is busy with results for another command

I am using Delphi XE using ADO connection to execute my queries on my SQL Server 2014. Please see below for my SQL Server Information :

---------------------- SQL Server 2014 INFO----------------------

Microsoft SQL Server Management Studio - 12.0.4522.0

Microsoft Analysis Services Client Tools - 12.0.4522.0

Microsoft Data Access Components (MDAC) - 10.0.17134.1

Microsoft MSXML - 3.0 6.0 

Microsoft Internet Explorer - 9.11.17134.0

Microsoft .NET Framework - 4.0.30319.42000

Operating System - 6.3.17134

---------------------- SQL Server 2014 INFO----------------------

Here is how I execute my ADOQuery

function TdataInterface.Query(SQLStr: String): TAdoQuery;
begin  
     Result := TADOQuery.Create(Self);
         Result.Prepared := True;
         try
            Result.Connection :=  <-- My AdoConnection Here -->;
            Result.SQL.Text   :=  SQLStr;
            if SQLStr <> '' then
               Result.Open;
         except
              On E:Exception do
              begin
                   ErrorLog('EException :  ' + E.Message);
                   {$IFDEF DEBUG}
                   ErrorLog('Query : [' + SQLStr + ']');
                   {$ENDIF}
                   Connected := False;
              end;
         end;
end;


(*
    Calling my ADOQuery function
*)

function THouseStark.AryasKill : Integer;
var
   ADOKill : TADOQuery;
begin
    ADOKill := TdataInterface.Query('SELECT COUNT(*) KillCount FROM got.AryasKill');
    try
       Result := ADOKill.FieldByName('KillCount').AsInteger
    finally
        FreeAndNil(ADOKill);
    end;
end;

My code works perfectly but there are instances that I got this exception

EException: Connection is busy with results for another command

It can't use any ADO queries every time this exception happen.

Any help? Is there something wrong or improvements in my code? Thank you.

Upvotes: 0

Views: 3382

Answers (1)

Adam T.
Adam T.

Reputation: 75

For me, helped setting TFDConnection's FetchOptions.Mode to fmAll.

Upvotes: 0

Related Questions