SQL Server Connection is busy with results for another command

laawzig2  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(90)

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.

kse8i1jr

kse8i1jr1#

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

相关问题