2013-12-11 5 views
0

SQL Server에서 잘 실행되는 spSchedulerCheck 저장 프로 시저가 있습니다. 단일 매개 변수 @jn을 사용합니다. 이것을 VB/ASP.Net에서 실행하려고하면 구문 오류가 발생합니다.Addwithvalue 인해 구문 오류가 발생했습니다.

VB 코드 :

Public Function ScheduleCheck() 
    Dim sText As String 
    Using cn As New System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("ProductionDatabaseConnectionString1").ConnectionString) 
     cn.Open() 
     Dim cmd As New System.Data.SqlClient.SqlCommand("SchedulerCheck", cn) 
     cmd.Parameters.AddWithValue("@jn", Trim(Request.QueryString("jn").ToString())) 
     Try 
      Using reader As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader() 
       If reader.Read() Then 
        sText = reader(0).ToString() 
       End If 
      End Using 
     Catch ex As Exception 
      Return ex.Message 
     End Try 

     If Not cn Is Nothing Then 
      cn.Close() 
     End If 
    End Using 
     Return sText 
End Function 

SP :이 밖으로 오류되지는 SP의 메시지 중 하나가 반환해야처럼

USE [Production Database 2] 
GO 

/****** Object: StoredProcedure [dbo].[SchedulerCheck] Script Date: 12/11/2013 15:31:48 ******/ 
SET ANSI_NULLS ON 
GO 

SET QUOTED_IDENTIFIER ON 
GO 

-- ============================================= 
-- Author:  <Author,,Name> 
-- Create date: <Create Date,,> 
-- Description: <Description,,> 
-- ============================================= 
CREATE PROCEDURE [dbo].[SchedulerCheck] 
    -- Add the parameters for the stored procedure here 
    @jn as nvarchar(max) 

AS 
BEGIN 
    -- SET NOCOUNT ON added to prevent extra result sets from 
    -- interfering with SELECT statements. 
    SET NOCOUNT ON; 

    -- Insert statements for procedure here 
declare @pn nvarchar(10); 
set @pn = (select Proposalnumber from tblprj_management where jobnumber = @jn); 

select ReturnCode = case 
    when not exists (select * from tblprj_equipmentscope where jobnumber = @jn) 
     then 'Could not find scope' 
    when not exists (select * from tblprj_frcriteria where jobnumber = @jn and 'FR' in (select equipment from tblprj_equipmentscope where jobnumber = @jn)) 
     then 'Could not find FR Criteria entry' 
    when not exists (select * from tblprj_wccriteria where jobnumber = @jn and 'WC' in (select equipment from tblprj_equipmentscope where jobnumber = @jn)) 
     then 'Could not find WC Criteria entry' 
    when not exists (select * from tblprj_sctcriteria where jobnumber = @jn and 'SCT' in (select equipment from tblprj_equipmentscope where jobnumber = @jn)) 
     then 'Could not find SCT Criteria entry' 
    when not exists (select * from tblprj_accriteria where jobnumber = @jn and 'AC' in (select equipment from tblprj_equipmentscope where jobnumber = @jn)) 
     then 'Could not find AC Criteria entry' 
    when not exists (select * from tblprj_LFcriteria where jobnumber = @jn and 'LF' in (select equipment from tblprj_equipmentscope where jobnumber = @jn)) 
     then 'Could not find LF Criteria entry' 
    when not exists (select * from tblprj_laborest where proposalnumber = @pn) 
     and not exists (select * from tblprj_mfglaborest assy where proposalnumber = @pn) 
     then 'Could not find labor estimates' 
    else 'Success' 
    end 


END 

GO 

나에게 보인다. 실제로 SQL 서버에서 실행하면 실제로 예상대로 실행됩니다. 일부 문제 해결은 매개 변수를 제공하지 않을 때 예상대로 실행되고 매개 변수를 전달하려고 시도 할 때 괴물 만 보여줍니다. 그게 오류의 원인이 뭐야?

편집 : 오류가 Syntax Error near SchedulerCheck

+0

무엇이 오류입니까? – Szymon

+0

하단의 편집에 추가되었습니다. – Crimius

답변

2

당신이 그렇지 않으면 CommandText에 SchedulerCheck 정상적인 SQL로 해석됩니다 StoredProcedure

Dim cmd As New System.Data.SqlClient.SqlCommand("SchedulerCheck", cn) 
    cmd.CommandType = CommandType.StoredProcedure 

Text의 기본에서 재산 CommandType을 변경해야 저장 프로 시저를 호출 할 때입니다 텍스트 (예 : SELECT/INSERT/UPDATE/DELETE). 물론 Syntax Error가 발생합니다.

AddWithValue 오류 메시지가 당신이 StoredProcedure로 명령의 CommandType를 설정해야

+0

주석으로 처리하면 오류 메시지없이 정상적으로 실행됩니다. 날 버렸어. 감사! 편집 : 매개 변수에 대한 기본값이 주어진 경우에만 그것은 보일 것입니다. 내 실수. – Crimius

2

과는 아무 상관이 없습니다. 기본값은 Text입니다.

cmd.CommandType = CommandType.StoredProcedure 
관련 문제