Cakephp / mssql中的游标状态无效

时间:2013-12-10 12:00:59

标签: php sql sql-server cakephp

我在cakephp上连接sql server 2008 r2。我需要拉取我已创建存储过程的excel,如下所示

ALTER procedure [dbo].[pullatm_card]
@date varchar(25)

as
begin
declare @sql as varchar(1000)
set @sql='INSERT INTO scts
(
terminal,
account_number,
txn_amount,
txn_date,
txn_tim,
trace_code
)

select 
f2 as terminal,
f6 as account_number,
f10 as txn_amount,
f14 as txn_date,
f22 as txn_time,
f27 as trace_code 
FROM OPENROWSET(''Microsoft.Jet.OLEDB.4.0'',
                ''Excel 8.0;Database=C:\rbl\sct\'+@date+'\excel\atm\cards.xls;IMEX=1'',
                ''SELECT * FROM [Sheet1$]'')

                where f14 is not null'

exec(@sql)          

当我开火时

exec pullatm_card'DEC01_2013EXCEL' on sql server query editor it is running sucessfully.

但是当我在下面的cakephp中尝试相同的时候

public function admin_add() {
        if ($this->request->is('post')) {
            //call three procedure here
            $date=$this->request->data['Sct']['date'];

            $this->Sct->query("exec pullatm_card"."'".$date."'");
            $this->Sct->query("exec pullatm_loro"."'".$date."'");
            $this->Session->setFlash(__('SCT record(s) been saved'));
            $this->redirect(array('action' => 'add'));

            }
    }

它会抛出错误,如下所示

Database Error
Error: SQLSTATE[24000]: [Microsoft][SQL Server Native Client 10.0]Invalid cursor state

SQL Query: exec pullatm_card'DEC01_2013EXCEL'

但是exec pullatm_card'DEC01_2013EXCEL'的结果被插入到数据库中并且它之后停止所有其他操作,即它下面的查询(参见php)不会被解雇?

可能是什么问题?

1 个答案:

答案 0 :(得分:0)