System.InvalidOperationException: String[1]: the Size property has an invalid size of 0. RRS feed

  • Question

  • Hi:

    I have a strang issue when calling ExecuteNonQuery with an output integer. The following is the detail of exception message:

    Instructions: Check exception detail and correct the problem. System.InvalidOperationException: String[1]: the Size property has an invalid size of 0.
       at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc)
       at System.Data.SqlClient.SqlCommand.SetUpRPCParameters(_SqlRPC rpc, Int32 startCount, Boolean inSchema, SqlParameterCollection parameters)
       at System.Data.SqlClient.SqlCommand.BuildRPC(Boolean inSchema, SqlParameterCollection parameters, _SqlRPC& rpc)
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
       at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
       at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
       at Microsoft.PME.Server.Data.PmeDbCommand.<>c__DisplayClass1.<ExecuteNonQuery>b__0() in e:\bt\935358\private\Server\StructuredStorage\DAL\Source\PmeDbCommand.cs:line 294
       at Microsoft.PME.Server.Data.ExponentialNRetryPolicy.Retry(Action action) in e:\bt\935358\private\Server\StructuredStorage\DAL\Source\ExponentialNRetryPolicy.cs:line 103
       at Microsoft.PME.Server.Data.PmeDbCommand.ExecuteNonQuery() in e:\bt\935358\private\Server\StructuredStorage\DAL\Source\PmeDbCommand.cs:line 309
       at Microsoft.PME.Server.GlobalDirector.GlobalDirectorDao.Impl.GlobalDirectorDaoImpl.GetNumUsers(String podName) in e:\bt\935358\private\Server\GlobalDirector\GlobalDirectorDao\Source\Impl\GlobalDirectorDaoImpl.cs:line 82

    The stored procedure looks like this:

        @podName        VARCHAR(30),
        @numUsers       INT OUT

     SELECT @numUsers = COUNT(PUID)
     FROM Subscriber
     WHERE Pod = @podName;

    The client code that calls the stored procedure looks like this:

    int numOfUsers = 0;                

      command.CommandText = "uspGDGetNumUsers";
                        command.CommandType = CommandType.StoredProcedure;

                        IDbDataParameter param = new new SqlParameter("@podName",  DbType.String);

                        param.Value = podName; // some string 

                        IDbDataParameter paramOut = new SqlParameter("@numUsers", DbType.Int32);
                        paramOut.Direction = ParameterDirection.Output;

                       paramOut.Value = numOfUsers;


                     numOfUsers = (int)paramOut.Value;

    I know there there is a bug in the abvoe client code: the SqlParameter constructor requires SqlDbType, not DbType, so it actually calls the SqlParamter(string, object) constructor and set the type to the Value property.

    However, the code works well in unit test and normal operation, it only fails after we stress tested the above client code for a while, and the exception seems to think the output paramter is a String type, which requires Size property to be set. but the actual output type is integer.

    Does anyone know what could be the cause of this?

    I had changed the client code to this:

    IDbDataParameter paramOut = new SqlParameter("@numUsers", SqlDbType.Int16);

    It also works in unit test, but I haven't had a chance to run stress test yet.



    Tuesday, May 4, 2010 8:08 PM