SqlServer ado连接 调用存储过程出 0x80020009 错

    @database = Sequel.ado(:conn_string=>conn, :provider=>"SQLNCLI10")

    @database.fetch "select * from Peopel.dbo.Hello"

    @database.run "exec Peopel.dbo.getmsg;"

 

   出现 下面错误

    OLE error code:800A0E78 in ADODB.Recordset

      Operation is not allowed when the object is closed.

    HRESULT error code:0x80020009

 

    在存储过程前加上 Set Nocount ON; 就可以了。

   @database.run "Set Nocount ON; exec Peopel.dbo.getmsg;"

   或者在存储过程的定义里的,开始处加上 set nocount on;  procedure ....; set nocount off.  这样也可以优化存储过程的速度。

   set nocount on 会关闭 Transact-SQL 语句中的 affect rows 输出, 当存储过程有多个select 或 insert, update 语句时, affect rows 会影响ado 的 dataset。

 

posted @ 2010-05-28 09:55  napoleon_liu  阅读(481)  评论(0编辑  收藏  举报