2015-06-18 15 views
6

Sto usando il server mssql con yii framework Ho creato uno stored-procedure si prega di vedere sotto il codice.SET NOCOUNT ON non funziona su ubuntu

//Call Store procedure to get data 
$sql = "EXECUTE IESReportData @assessmentId=:assessmentId, @queId=:queId,@instanceId=:instanceId"; 
//set database connection and start the yii query builder to be executed. 
$connection = Yii::app()->db; 
$command = $connection->createCommand($sql); 
$command->bindValue(":assessmentId", $assessmentId); 
$command->bindValue(":queId", ""); 
$command->bindValue(":instanceId", "$instanceId"); 
$Reportresults = $command->queryAll(); 

Questo funziona bene sotto ubuntu ambiente ma dà errore sotto sotto windows ambiente.

Fatal error: Uncaught exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: SQLSTATE[IMSSP]: The active result for the query contains no fields. 

con un po 'di R & D ho scoperto che abbiamo bisogno di SET NOCOUNT ON così ho cambiato sotto dichiarazione

$sql = "SET NOCOUNT ON EXECUTE IESReportData @assessmentId=:assessmentId, @queId=:queId,@instanceId=:instanceId"; 

Questo funziona bene in window, ma fornire risultato nullo sotto ubuntu ambiente.

Per favore aiutatemi.

+3

Perché non mettere 'SET NOCOUNT on' all'interno del proc memorizzato? – Andrew

+0

Grazie Andrew, ho messo "SET NOCOUNT ON" dentro la stored procedure e ora funziona. – Jayson

risposta

3

sotto è esempio per l'impostazione NOCOUNT ON nella stored procedure

SET ANSI_NULLS ON 
 
GO 
 
SET QUOTED_IDENTIFIER ON 
 
GO 
 
-- ============================================= 
 
-- Author: <Author,,Name> 
 
-- Create date: <Create Date,,> 
 
-- Description: <Description,,> 
 
-- ============================================= 
 
CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName> 
 
-- Add the parameters for the stored procedure here 
 
<@Param1, sysname, @p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>, 
 
<@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0> 
 
AS 
 
BEGIN 
 
-- SET NOCOUNT ON added to prevent extra result sets from 
 
-- interfering with SELECT statements. 
 
SET NOCOUNT ON; 
 

 
-- Insert statements for procedure here 
 
SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2> 
 
END`enter code here` 
 
GO

+0

Grazie Kevin, ho messo "SET NOCOUNT ON" dentro la stored procedure e ora funziona. – Jayson

Problemi correlati