Domanda

so i have a program in C# that accesses a old Firebird 1.5 database from a third party program. One of the methods i have will fetch data for either a quote or a project by id: (sorry about some Portuguese words in there)

public static List<object> GetFollowUpData(int id, TipoFollowUp tipo)
    {
        var res = new List<object>();
        string q = tipo == TipoFollowUp.Orcamento
            ? "SELECT ('Q-' || c.CLIENT_CODE || q.CQUO_FNUMB) as Codigo, q.CQUO_NAME as Nome, q.CQUO_SENT as Data, q.CQUO_TOTAL as Total, c.CLIENT_NAME as Empresa, m.CCON_NAME as Contacto, ((CASE WHEN m.CCON_PHONE1 IS null then '' else m.CCON_PHONE1 end) || '/' || (CASE WHEN m.CCON_PHONE2 IS null then '' else m.CCON_PHONE2 end) || '/' || (CASE WHEN m.CCON_PHONE3 IS null then '' else m.CCON_PHONE3 end) || '/' || (CASE WHEN m.CCON_PHONE4 IS null then '' else m.CCON_PHONE4 end) || '/' || (CASE WHEN c.CLIENT_PHONE1 IS null then '' else c.CLIENT_PHONE1 end) || '/' || (CASE WHEN c.CLIENT_PHONE2 IS null then '' else c.CLIENT_PHONE2 end) || '/' || (CASE WHEN c.CLIENT_PHONE3 IS null then '' else c.CLIENT_PHONE3 end) || '/' || (CASE WHEN c.CLIENT_PHONE4 IS null then '' else c.CLIENT_PHONE4 end)) as Telefones FROM CMULTIQUOTES q, CLIENTS c, CCONTACTS m WHERE q.ID = @id AND c.CLIENT_ID = q.CLIENT_ID AND q.CLIENT_PM = m.CCON_ID"
            : "SELECT q.PROJ_CODE as Codigo, q.PROJ_NAME as Nome, q.PROJ_COMPLETED as Data, (select sum(j.CJOB_TOTAL) from CJOBS j where j.PROJ_ID = @id) as Total, c.CLIENT_NAME as Empresa, m.CCON_NAME as Contacto, ((CASE WHEN m.CCON_PHONE1 IS null then '' else m.CCON_PHONE1 end) || '/' || (CASE WHEN m.CCON_PHONE2 IS null then '' else m.CCON_PHONE2 end) || '/' || (CASE WHEN m.CCON_PHONE3 IS null then '' else m.CCON_PHONE3 end) || '/' || (CASE WHEN m.CCON_PHONE4 IS null then '' else m.CCON_PHONE4 end) || '/' || (CASE WHEN c.CLIENT_PHONE1 IS null then '' else c.CLIENT_PHONE1 end) || '/' || (CASE WHEN c.CLIENT_PHONE2 IS null then '' else c.CLIENT_PHONE2 end) || '/' || (CASE WHEN c.CLIENT_PHONE3 IS null then '' else c.CLIENT_PHONE3 end) || '/' || (CASE WHEN c.CLIENT_PHONE4 IS null then '' else c.CLIENT_PHONE4 end)) as Telefones FROM PROJECTS q, CLIENTS c, CCONTACTS m WHERE q.PROJ_ID = @id AND c.CLIENT_ID = q.CLIENT_ID AND q.CLIENT_PM = m.CCON_ID";
        using (var cmd = new FbCommand(q) {CommandType = CommandType.StoredProcedure})
        using (cmd.Connection = new FbConnection(ConnectionString))
        {
            cmd.Connection.Open();
            cmd.Parameters.Add("@id", id);
            using (FbDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    res.Add(id); // ID
                    res.Add(reader[0]); // Código
                    res.Add(reader[1]); // Nome
                    res.Add(reader[2]); // Data
                    res.Add(reader[3]); // Total
                    res.Add(reader[4]); // Empresa
                    res.Add(reader[5]); // Contacto
                    res.Add(reader[6]); // Telefones
                    res.Add(tipo); // Tipo
                }
                reader.Close();
            }
            cmd.Connection.Close();
        }
        return res;
    }

This works most of the time - but for a specific project it's not returning any data (project id 8771)

I've copy pasted the second query into FlameRobin, connected it to the database and replaced @id in the query with 8771 and flameRobin returns the data i want.

So if FlameRobin can get the data using my query, why doesn't my program get it too? in My method above, Reader.Read() imediatly returns false and i get no data from the database for that project. Other projects and quotes so far had no issues returning the data as far as i've detected

Anyone ahs any ideas?

È stato utile?

Soluzione

Sorry everyone Just spent half a morning around this to finally figure out i was using my development/test database copy in the program (under VS) and connecting to the production copy in FlameRobin.

Lack of sync between the tw databases was causing this

The project in question existed in the production copy - thus FlameRobin was showing it - but not in the development/test copy used by the program

Sorry

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top