title: Declare the length of a MSSQL output parameter called from C#
body: <p>I have a mssql store procedure with two parameters input, output.</p>
  
  <pre><code>CREATE PROCEDURE SP_Test1
          @Pi_Action          INT,
          @Pv_ErrorMessage    VARCHAR(250)    OUTPUT
  </code></pre>
  
  <p>I am executing this procedure from my application in this way.</p>
  
  <pre><code>DbManager dbManager = new DbManager();
  dbManager.ProcName = "SP_Test1";
  dbManager.addParam("@Pi_Action", SqlDbType.Int, ParameterDirection.Input, 3);
  dbManager.addParam("@Pv_ErrorMessage", SqlDbType.VarChar, ParameterDirection.Output, null);
          bool resultado = dbManager.executeProc();
  </code></pre>
  
  <p>I have a class called DbManager with two methods.</p>
  
  <pre><code>    public void addParam(string paramName, SqlDbType paramType, ParameterDirection paramDirection, object paramValue)
      {
        parametros.Add(new Parametro(paramName, paramType, paramDirection, paramValue));
      }
  
      public bool executeProc()
      {
          using (SqlConnection sqlConnection = new SqlConnection(connStr))
          {
             SqlCommand sqlComm = new SqlCommand();
             sqlComm.Connection = sqlConnection;
             sqlComm.CommandText = ProcName;
             sqlComm.CommandType = CommandType.StoredProcedure;
  
             SqlParameter sqlPar = null;
             foreach(Parametro parametro in parametros)
             {
                sqlPar = new SqlParameter();
                sqlPar.ParameterName = parametro.paramName;
                sqlPar.SqlDbType = parametro.paramType;
                sqlPar.Direction = parametro.paramDirection;
                sqlPar.Value = parametro.paramValue;
                //sqlPar.Size = 300;
                sqlComm.Parameters.Add(sqlPar);
             }
             sqlConnection.Open();
             sqlComm.ExecuteNonQuery();
  
             String parVal = (String)sqlComando.Parameters["@Pv_ErrorMessage"].Value;
  
             return true;
           }
  </code></pre>
  
  <p>In the time that I get the value of the output parameter, this returns me only the first letter of the string.
  I must always declare the length of the string parameters?
  Exists a way I can avoid to declare the length of the string parameters and return me the whole string?</p>
  
  <p>Thanks for your help.</p>