2015-06-18 14 views
6

Tôi đang sử dụng máy chủ mssql với yii framework Tôi đã tạo một stored-procedure vui lòng xem mã bên dưới.SET NOCOUNT ON không hoạt động trong 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(); 

Điều này hoạt động tốt dưới môi trường ubuntu nhưng nó có lỗi dưới môi trường windows.

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. 

với một số R & D Tôi thấy rằng chúng ta cần phải SET NOCOUNT ON vì vậy tôi đã thay đổi dưới đây tuyên bố

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

này hoạt động tốt trong window, nhưng nó cung cấp kết quả rỗng dưới ubuntu môi trường.

Hãy giúp tôi.

+3

Tại sao không đưa 'thiết nocount on' bên trong proc lưu trữ của bạn? – Andrew

+0

Cảm ơn Andrew, tôi đã đặt 'SET NOCOUNT ON' bên trong thủ tục lưu sẵn và nó đang hoạt động ngay bây giờ. – Jayson

Trả lời

3

dưới đây là ví dụ cho việc thiết nocount trên trong thủ tục lưu trữ

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

Cảm ơn Kevin, tôi đã đặt 'SET NOCOUNT ON' vào trong thủ tục lưu sẵn và nó đang hoạt động. – Jayson

Các vấn đề liên quan