I have a set of stored procedures that I am using to populate an ASP.Net CheckBoxList. When running this procedure from code as { CALL ProcedureName(params); } with the type set as stored procedure, I only seem to be getting a partial result back (i.e. many columns from the actual result are missing.)
If I copy the CommandText from the query (having used a breakpoint to get the exact text sent) and run it directly in Navicat (or any other MySQL GUI), I get all of the expected columns.
Here is the code that is not working:
using (OdbcCommand command = OdbcConnection.CreateCommand())
{
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "{ " + string.Format(StoredProcedureCall, foundationId, fpids, "", "", "NULL", "2001/01/02", "2001/01/01", "*") +
" }";
using (OdbcDataReader reader = command.ExecuteReader())
{
for (int i = 0; i < reader.FieldCount; i++)
{
columns.Add(reader.GetName(i));
}
}
}
If I change the code to the following however it starts to work (only adding the other using):
using (OdbcConnection)
using (OdbcCommand command = OdbcConnection.CreateCommand())
{
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "{ " + string.Format(StoredProcedureCall, foundationId, fpids, "", "", "NULL", "2001/01/02", "2001/01/01", "*") +
" }";
using (OdbcDataReader reader = command.ExecuteReader())
{
for (int i = 0; i < reader.FieldCount; i++)
{
columns.Add(reader.GetName(i));
}
}
}
What is going on here?
For reference here is the OdbcConnection property:
public static OdbcConnection OdbcConnection
{
get
{
// If we have no connection or our connection isn't open
if (null == odbcConnection || ConnectionState.Open != odbcConnection.State)
{
odbcConnection = new OdbcConnection(BaseAccess.DBConnectionString);
odbcConnection.Open();
}
return odbcConnection;
}
}