0

我有一个 WebService 来获取由 android 应用程序发送的音频文件,但是当我尝试导出时,我在 WebService 中收到此错误:

2013-10-09 09:41:07,486 [18] ERROR Caderneta.ArquivosDAO 
  ArquivosDAO.cs: Falha -> InsertAudio
System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@IdImagem".
   at System.Data.SqlClient.SqlConnection.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.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.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at Caderneta.ArquivosDAO.InsertAudio(Audio arquivos, String idponto) in C:\Users\Leandro\Documents\Visual Studio 2010\Projects\Caderneta\Caderneta\ArquivosDAO.cs:line 75
ClientConnectionId:b5e32e72-8c84-4585-8302-d3dd0681e23d

这是 SQL 命令:

cmdInsertVoz.CommandText = "INSERT INTO Voz (IdVoz, IdPonto, IdContextoVoz, IdImagem, DadoVoz, FlagUpload, IdMovel) VALUES(@IDVOZ, @IDPONTO, @IDCONTEXTO, @IdImagem, @DADOSVOZ, 0, @IDMOVEL)";

这是插入音频的方法:

public void InsertAudio(Audio arquivos, String idponto)
        {
            try
            {
                cmdInsertVoz.Transaction = tran;

                String IdVozes = criaId(idponto, 2);
                    cmdInsertVoz.Parameters.AddWithValue("@IDVOZ", IdVozes);

                    cmdInsertVoz.Parameters.AddWithValue("@IDPONTO", idponto);
                    cmdInsertVoz.Parameters.AddWithValue("@IDCONTEXTO", Convert.ToInt32(arquivos.contexto));
                    if (IdVozes.Length == 11)
                    {
                        cmdInsertVoz.Parameters.AddWithValue("@IdImagem", IdVozes.Substring(0, 9));
                    }

                    byte[] vozBytes = Convert.FromBase64String(arquivos.arquivo);
                    cmdInsertVoz.Parameters.AddWithValue("@DADOSVOZ", vozBytes);
                    cmdInsertVoz.Parameters.AddWithValue("@IDMOVEL", arquivos.idmovel);
                    cmdInsertVoz.ExecuteNonQuery();
                    log.Info("exec");
                    cmdInsertVoz.Parameters.Clear();
                    log.Debug("gravado arquivo de áudio");

            }catch(Exception e){

                this.log.Error("ArquivosDAO.cs: Falha -> InsertAudio", e);
                throw e;
            }

        }

我真的陷入了这个错误,不知道在这种情况下我做错了什么。

4

0 回答 0