Why only some users get the error: “Connection is busy with results for another command”

后端 未结 6 867
夕颜
夕颜 2021-02-08 16:06

I have a Delphi Application that is connected to a SQL Server db using SDAC component from DevArt, we have 200 installations of the software and only to a customer, with some us

相关标签:
6条回答
  • 2021-02-08 16:22

    To provide Multiple Active Result Set (MARS) support to a SQL connection using the MSSQL driver, you must add a key called Mars_Connection and set its value to True.

    0 讨论(0)
  • 2021-02-08 16:34

    Just wanted to correct dataol's answer and say that MARS_Connection should be set to "Yes" instead of "True" to enable Multiple Active Result Sets. At least on SQL Server 2012 if you are using a DSN file:

    [ODBC]
    DRIVER=SQL Server Native Client 11.0
    DATABASE=MYDBNAME
    WSID=
    Trusted_Connection=Yes
    SERVER=
    MARS_Connection=Yes
    
    0 讨论(0)
  • 2021-02-08 16:34

    @ienax_ridens, I recently encountered the same problem using the same tools (Delphi and Devart-SDAC). In my case one specific query giving two results sets. My TMSQuery was

    If Condition= 1 
    begin
     Select * from #TempTable1
    end else 
    begin
      -- Some more stuff
      Insert INTO #TempTable2
     --
     --
    End
    Select * from TempTable1 -- here is the problem
    

    so in case of Condition = 1 it was giving two results sets and causing "Connection is busy with results for another command"

    I hope this helps you.

    Edit: I realized you post is quite old, please share what you did to resolve this error

    0 讨论(0)
  • 2021-02-08 16:38

    Check your compatibility mode i just ran into this when we moved from 2008 to 2016 db we had to set it to 2012 compatibility mode.

    0 讨论(0)
  • 2021-02-08 16:44

    The "Connection is busy with results for another command" error means that there are at least two queries that use the same connection. This problem can occur if you are using one connection in several threads. To solve the problem in this case, you should have connection (the TMSConnection component) in each thread. Also, this problem can occur if you set the TCustomMSDataSet.FetchAll property to False. When FetchAll=False, execution of such queries blocks the current session. In order to avoid blocking OLEDB creates additional session that can cause the "Connection is busy with results for another command" error. To solve the problem in this case, you should set the TMSConnection.Options.MultipleActiveResultSets property to True. The MultipleActiveResultSets property enables support for the SQL Server Multiple Active Result Sets (MARS) technology. It allows applications to have more than one pending request per connection, and, in particular, to have more than one active default result set per connection. Please note that the MultipleActiveResultSets property works only when SQL Native Client is used. Therefore, you should also set the TMSConnection.Options.Provider property to prNativeClient.

    0 讨论(0)
  • 2021-02-08 16:46

    I had the same problem and solved installing the microsoft odbc driver 11 (msodbcsql) (https://www.microsoft.com/pt-br/download/confirmation.aspx?id=36434).

    0 讨论(0)
提交回复
热议问题