У меня есть хранимая процедура SQL Server 2008, которая при вызове с помощью приведенного ниже кода возвращает исключение отсутствующего параметра для параметра @BatchID
.SQL Stored Call не передает параметр
Как вы можете видеть, я передаю в параметре с
cmd.Parameters.AddWithValue("@BatchID", batchID)
, но по какой-то причине его не собирание его при выполнении вызова к серверу.
Возможно, здесь что-то не так просто, это был долгий день.
Хранимая процедура
ALTER PROCEDURE [dbo].[spIsEngineSixCylinderByBatchID]
@BatchID as int
AS
BEGIN
SET NOCOUNT ON;
DECLARE @IsSixCylinder as bit
SET @IsSixCylinder = 0
SELECT @IsSixCylinder = tblBatches.SixCylinder
FROM tblBatches
WHERE IdBatch = @BatchID
SELECT @IsSixCylinder
END
Код
Private Function IsBatchSixCylinder(batchID As Int32) As Boolean
Dim isSixCylinder As Boolean = False
Try
Using cmd As New SqlClient.SqlCommand("[dbo].[spIsEngineSixCylinderByBatchID]", _conn)
cmd.Parameters.AddWithValue("@BatchID", batchID)
isSixCylinder = cmd.ExecuteScalar
End Using
Catch ex As SqlClient.SqlException
LogError(ex.Message)
End Try
Return isSixCylinder
End Function
Исключение
процедура или функция ожидает '' spIsEngineSixCylinderByBatchID параметр '@BatchID', который не был указан.
Call Stack
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteScalar()
at ClassLib_SAPtoEPMS.clsSAPtoEPMS.IsBatchSixCylinder(Int32 batchID) in C:\Users\phil.murray\Desktop\EPMS_05022012\EPMS_05022012\Power Systems EPMS\ClassLib_SAPtoEPMS\ClassLib_SAPtoEPMS\clsSAPtoEPMS.vb:line 229
Включено 'cmd.CommandType = CommandType.StoredProcedure' в редактировании –
Думал CommandType по умолчанию был StoredProcedure ??? Это сработало, но я сейчас смущен. –
См. Http://stackoverflow.com/questions/9799524/expects-parameter-id-which-was-not-supplied –