Home All Groups Group Topic Archive Search About

how to fix error "Connection is busy with results for another hstmt"



Author
24 Jun 2009 10:55 AM
vijay singh
Platform: VS 2008, SQL Server 2005, OleDB



Hi,



I am using OleDB connection in vc++ code to insert data in sql server
database. Single connection is being used by multiple threads to insert
data. Sometime program is reporting error "Connection is busy with results
for another hstmt".



Please help me how this issue can be resolved.



Thanks,



Vijay

Author
24 Jun 2009 12:32 PM
Dan Guzman
> Sometime program is reporting error "Connection is busy with results for
> another hstmt".

This error indicates that a prior command on the connection is still
executing or the results have not been processed completely.  Ensure that
all results are retrieved before attempting another command on the
connection.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

Show quoteHide quote
"vijay singh" <vijaysi***@abosoftware.com> wrote in message
news:Oh119oL9JHA.200@TK2MSFTNGP05.phx.gbl...
Are all your drivers up to date? click for free checkup

Author
25 Jun 2009 4:02 AM
vijay singh
Environment: MS SQL Server 2005, VS 2008/VC++, W2K3 R2

Sorry, I should have been clearer.

For my simultaneous database inserts (additions/forward only; no edits)
from different threads not requiring any result back and not requiring any
transitioning, I was hoping that I could use a single database connection
without locking for such inserts  (no need to sequence inserts one by one on
the same connection). I use OLEDB and I am able to do this with Oracle
Database and Postgress database. However, when I use MS SQL Server database,
I get his error "Connection is busy with results for another hstmt".

How do I achieve simultaneous inserts in above scenario with single
database connection without have to lock it or issue insert commands one by
one?

Thanks,

Vijay
Show quoteHide quote
"Dan Guzman" <guzmanda@nospam-online.sbcglobal.net> wrote in message
news:%23$M3VfM9JHA.1380@TK2MSFTNGP02.phx.gbl...

>> Sometime program is reporting error "Connection is busy with results for
>> another hstmt".
>
> This error indicates that a prior command on the connection is still
> executing or the results have not been processed completely.  Ensure that
> all results are retrieved before attempting another command on the
> connection.
>
> --
> Hope this helps.
>
> Dan Guzman
> SQL Server MVP
> http://weblogs.sqlteam.com/dang/
>
> "vijay singh" <vijaysi***@abosoftware.com> wrote in message
> news:Oh119oL9JHA.200@TK2MSFTNGP05.phx.gbl...
Author
25 Jun 2009 11:43 AM
Dan Guzman
> How do I achieve simultaneous inserts in above scenario with single
> database connection without have to lock it or issue insert commands one
> by one?

The SQLOLEDB driver doesn't allow concurrent batches on a single connection,
I believe the SQL Server Native Client OLEDB driver (SQLNCLI) will allow
multiple concurrent batches this with MARS enabled.  I have not personally
seen MARS used for multi-threaded inserts since the overhead of multiple
connections in SQL Server isn't that significant; one usually employs
separate connections.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

Show quoteHide quote
"vijay singh" <vijaysi***@abosoftware.com> wrote in message
news:%23qJLOnU9JHA.3544@TK2MSFTNGP04.phx.gbl...
> Environment: MS SQL Server 2005, VS 2008/VC++, W2K3 R2
>
> Sorry, I should have been clearer.
>
> For my simultaneous database inserts (additions/forward only; no edits)
> from different threads not requiring any result back and not requiring any
> transitioning, I was hoping that I could use a single database connection
> without locking for such inserts  (no need to sequence inserts one by one
> on the same connection). I use OLEDB and I am able to do this with Oracle
> Database and Postgress database. However, when I use MS SQL Server
> database, I get his error "Connection is busy with results for another
> hstmt".
>
> How do I achieve simultaneous inserts in above scenario with single
> database connection without have to lock it or issue insert commands one
> by one?
>
> Thanks,
>
> Vijay
> "Dan Guzman" <guzmanda@nospam-online.sbcglobal.net> wrote in message
> news:%23$M3VfM9JHA.1380@TK2MSFTNGP02.phx.gbl...
>
>>> Sometime program is reporting error "Connection is busy with results for
>>> another hstmt".
>>
>> This error indicates that a prior command on the connection is still
>> executing or the results have not been processed completely.  Ensure that
>> all results are retrieved before attempting another command on the
>> connection.
>>
>> --
>> Hope this helps.
>>
>> Dan Guzman
>> SQL Server MVP
>> http://weblogs.sqlteam.com/dang/
>>
>> "vijay singh" <vijaysi***@abosoftware.com> wrote in message
>> news:Oh119oL9JHA.200@TK2MSFTNGP05.phx.gbl...
>
>
Author
25 Jun 2009 10:11 PM
Erland Sommarskog
Dan Guzman (guzmanda@nospam-online.sbcglobal.net) writes:
>> How do I achieve simultaneous inserts in above scenario with single
>> database connection without have to lock it or issue insert commands one
>> by one?
>
> The SQLOLEDB driver doesn't allow concurrent batches on a single
> connection, I believe the SQL Server Native Client OLEDB driver
> (SQLNCLI) will allow multiple concurrent batches this with MARS enabled.
>  I have not personally seen MARS used for multi-threaded inserts since
> the overhead of multiple connections in SQL Server isn't that
> significant; one usually employs separate connections.

Actually, by default SQLOLEDB does. It will open a second physical
connection if the connection is busy.

However, since Vijay get an error message talking about hstmt, he is
obviously not using SQLOLEDB, but MSDASQL, because hstmt is an ODBC
thing.

MARS could be an option, but Vijay did not want to lock his connection
and get serialisation. Since MARS means execution in an interleaved
fashion, that is in fact serialisation.

Vijay should have one conenction per thread, or connect and disconnect
every time he performs an operation. Connection pooling will make sure
that there is no physical disconnection, as long as the connections are
reused within 60 seconds.

--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Author
26 Jun 2009 2:06 AM
Dan Guzman
> Actually, by default SQLOLEDB does. It will open a second physical
> connection if the connection is busy.

I've always been under the impression that the second connection was
something that ADO did; I didn't know that it was SQLOLEDB doing this dirty
work.

> MARS could be an option, but Vijay did not want to lock his connection
> and get serialisation. Since MARS means execution in an interleaved
> fashion, that is in fact serialisation.

You are right - interleaved and concurrent are not the same thing.

> Vijay should have one conenction per thread, or connect and disconnect
> every time he performs an operation. Connection pooling will make sure
> that there is no physical disconnection, as long as the connections are
> reused within 60 seconds.

+1

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

Show quoteHide quote
"Erland Sommarskog" <esq***@sommarskog.se> wrote in message
news:Xns9C361EF9E8DBYazorman@127.0.0.1...
> Dan Guzman (guzmanda@nospam-online.sbcglobal.net) writes:
>>> How do I achieve simultaneous inserts in above scenario with single
>>> database connection without have to lock it or issue insert commands one
>>> by one?
>>
>> The SQLOLEDB driver doesn't allow concurrent batches on a single
>> connection, I believe the SQL Server Native Client OLEDB driver
>> (SQLNCLI) will allow multiple concurrent batches this with MARS enabled.
>>  I have not personally seen MARS used for multi-threaded inserts since
>> the overhead of multiple connections in SQL Server isn't that
>> significant; one usually employs separate connections.
>
> Actually, by default SQLOLEDB does. It will open a second physical
> connection if the connection is busy.
>
> However, since Vijay get an error message talking about hstmt, he is
> obviously not using SQLOLEDB, but MSDASQL, because hstmt is an ODBC
> thing.
>
> MARS could be an option, but Vijay did not want to lock his connection
> and get serialisation. Since MARS means execution in an interleaved
> fashion, that is in fact serialisation.
>
> Vijay should have one conenction per thread, or connect and disconnect
> every time he performs an operation. Connection pooling will make sure
> that there is no physical disconnection, as long as the connections are
> reused within 60 seconds.
>
> --
> Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se
>
> Links for SQL Server Books Online:
> SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
> SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
> SQL 2000:
> http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
>

Bookmark and Share