2017-03-24 1 views
1

여기에 온 전성 검사가 필요합니다. 매우 간단한 ExecuteNonQuery가 있습니다. 나는 sproc에 값을 전달하지만 첫 번째 값도 통과하지 못했다는 오류를 반환합니다.매개 변수가 SQL에 전달되지 않음 프로 시저

using (SqlConnection sqlConnection = new SqlConnection(ConnectionString)) 
       { 
        sqlConnection.Open(); 
        using (SqlCommand sqlCommandLogError = new SqlCommand("MyStoredProc", sqlConnection)) 
        { 
         sqlCommandLogError.Parameters.AddWithValue("logEntry", logEntry); 
         sqlCommandLogError.Parameters.AddWithValue("EventLogEntryType", EventLogEntryType); 
         sqlCommandLogError.Parameters.AddWithValue("EventID", eventId); 
         sqlCommandLogError.ExecuteNonQuery(); 

       } 
      } 

는 내가 실제로 SPROC의 필드가 정확 있는지 확인하는 절차에 그들을 널링이 일 해당 매개 변수 (이것은 데이터베이스의 모든 널 (null)을 넣어)

절차에 존재 확인

프로 시저에서 매개 변수가 전달되지 않는다고 생각하는 이유는 무엇입니까?

업데이트] 질문 이것은 내가 그들의 밖으로 전문가의 어떤 사랑을 듣고 대답 있는데도 : 필요한 매개 변수의 @symbol이 (그렇지 않은 것 같다)이며 왜도에 넣지 않고 내 SPROC을 찾을 것입니다 명령 유형.

+2

는 당신의 StoredProcedure로하는 SqlCommand의 CommandType을 속성을 설정해야합니다. –

답변

1

시도해보십시오. 키 이름에 @을 추가하십시오.

using (SqlConnection sqlConnection = new SqlConnection(ConnectionString)) 
{ 
    sqlConnection.Open(); 
    using (SqlCommand sqlCommandLogError = new SqlCommand("MyStoredProc", 
      sqlConnection)) 
    { 
     sqlCommandLogError.CommandType = CommandType.StoredProcedure; 

     sqlCommandLogError.Parameters.AddWithValue("@logEntry", logEntry); 
     sqlCommandLogError.Parameters.AddWithValue("@EventLogEntryType", 
               EventLogEntryType); 
     sqlCommandLogError.Parameters.AddWithValue("@EventID", eventId); 

     sqlCommandLogError.ExecuteNonQuery(); 
    } 
} 
+0

실제로 나는 그것에서 @를 지켰다. 필수는 아닙니다. 명령 유형을 잊어 버렸습니다. (이상한 점은 메시지가 매개 변수가 누락되었다고 말하고 있지만 사실 commandType이 누락되었다는 것입니다. 나는 sproc을 찾지도 못했을 것이라고 예상 했었습니다. commandType. – logixologist

0

SQL Server 저장 프로 시저 "MyStoredProc"의 소스 코드가 첨부되어 있지 않기 때문에 정확한 대답을 찾기가 어렵습니다. 사용 가능한 정보에 따라 저장 프로 시저 매개 변수 이름 앞에는 "@"문자가 와야합니다.

0

당신은 @와 SQLTYPE와 같은 매개 변수의 이름을 전달해야합니다

using (SqlConnection sqlConnection = new SqlConnection(ConnectionString)) 
      { 
       sqlConnection.Open(); 
       using (SqlCommand sqlCommandLogError = new SqlCommand("MyStoredProc", sqlConnection)) 
       { 
        sqlCommandLogError.Parameters.Add(new SqlParameter("@logEntry", SqlDbType.YourParamType) {Value = logEntry}); 
        sqlCommandLogError.Parameters.Add(new SqlParameter("@EventLogEntryType", SqlDbType.YourParamType) {Value = EventLogEntryType}); 
        sqlCommandLogError.Parameters.Add(new SqlParameter("@EventID", SqlDbType.YourParamType) {Value = eventId}); 

        sqlCommandLogError.ExecuteNonQuery(); 

      } 
     } 
+0

나는 투표를하지 않겠지 만, 당신이 정말로 틀린 것을 놓치고 있습니다. 내 오류의 이유는 CommandType 선언이 누락 되었기 때문입니다. – logixologist