SQL Server连接占线

使用ADO及ODBC连接SQL Server时,如果连接没有处理好,很容易出现下面的错误:

[Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt.
连接占线导致另一个hstmt。

[Microsoft][ODBC SQL Server Driver]Connection is busy with results for another command.
连接占线导致另一个命令。

产生这个错误的原因是,在同一个connection中,同时操作了多个数据集。

解决这个问题有两个方法
1、不要在一个connection中,同时打开多个数据集
2、在SQL SERVER2005以上版本,可以使用MARS (Multiple Active ResultSet)。在连接字符串中加上”Mars_Connection=yes;”就可以支持多数据集了。

关于MARS,可以参考这个:
http://msdn2.microsoft.com/en-us/library/ms345109.aspx

Leave a Reply

Your email address will not be published. Required fields are marked *

*