Bonjour à tous,

Je suis actuellement en train de développer une application. J'ai différents objets qui se remplissent d'autres objets. Pour optimiser mes connexions à la base de données j'ai imbriqué toutes mes requêtes.

Hier matin tout tournait parfaitement, mais après deux ou trois modifications mineures, je ne peux plus exécuter ma requête sans une perpétuelle erreur qui me dit qu'un reader est déjà ouvert et qu'il faut que je le ferme avant d'en demander un nouveau, seulement si je le ferme, lors de la boucle suivante le programme plante et me dit que le SQLDataReader est fermé et qu'il ne peut donc pas lire les données, je ne parviens vraiment pas à trouver le bug. Si quelqu'un le voit, je suis vraiment preneuse, je suis dessus depuis 24h, je sèche ...

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
 
    public family load_family(int id_manufacturer, int id_family)
    {
        family myFamily = new family(id_manufacturer, id_family);
        this.connexion.Connect();
        SqlCommand command = new SqlCommand
        (...);
        SqlDataReader reader = command.ExecuteReader();
        if (this.reader.HasRows)
        {
            while (reader.Read())
            {
                child_family tmpChild = new child_family (...);
                SqlDataReader readerProduct = commandProduct.ExecuteReader();
                if (readerProduct.HasRows)
                {
                    while (readerProduct.Read())
                    {
                        product myProduct = new product(...);
                        SqlCommand commandCaracteristic = new SqlCommand("getCaracteristicsFromSampler", this.connexion.connectToDB);
                        (...);
                        SqlDataReader readerCaracteristic = commandCaracteristic.ExecuteReader();
                        if (readerCaracteristic.HasRows)
                        {
                            while (readerCaracteristic.Read())
                            {
                                caracteristic myCaracteristic = new caracteristic(...);
                                SqlCommand commandValue = new SqlCommand("getValueCaracteristicFromIdProductAndCaracteristic", this.connexion.connectToDB);
                                (...);
                                SqlDataReader readerValue = commandValue.ExecuteReader();
                                if (readerValue.HasRows)
                                {
                                    readerValue.Read();
                                    myCaracteristic.value = readerValue["VALEUR_CARACTERISTIQUE"].ToString();
                                }
                                readerValue.Close();
                                (...);
                                SqlCommand commandCommission = new SqlCommand(requestSQL, this.connexion.connectToDB);
                               (...);
                                SqlDataReader readerCommission = commandCommission.ExecuteReader();
                                if (readerCommission.HasRows)
                                {
                                    while (readerCommission.Read())
                                    {
                                        commission myCommission = new commission(readerCommission["DATE_PRELEVEMENT"].ToString().Trim());
                                        myProduct.commissions.Add(myCommission);
                                    }
                                }
                                readerCommission.Close();
                                myProduct.caracteristics.Add(myCaracteristic);
                            }
                        }
                        readerCaracteristic.Close();
                        tmpChild.products.Add(myProduct);
                    }
                }
                this.readerProduct.Close();
                myFamily.child_families.Add(tmpChild);
            }
        }
        this.reader.Close();
        connexion.Close();
        return (myFamily);
    }