Bonjour, j'essaye de se connecter à une base de donnée pour récupérer des données, le programme me lance une exception comme quoi la connexion n'a pas était fermé, alors qu'en vraie je la ferme aprés chaque connexion et mme quand j’exécute en mode débogage je vois bien l'état de connexion "Closed", quelqu'un à une idée sur la solution de ce probléme
Merci

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class AdoSixDof
    {
        public List<double> sixval = new List<double>();
        public string TheConnectionString;
        public SqlConnection Cnx;
        public SqlCommand Cmd;
        public AdoSixDof(string TheConnection)
        {
            this.TheConnectionString = TheConnection;
            Cnx = new SqlConnection(TheConnectionString);
        }
        public void OpenConnection()
        {
            if (this.Cnx.State != System.Data.ConnectionState.Open)
            {
                Cnx.Open();
            }
        }
        public void CloseConnection()
        {
            if (this.Cnx.State != System.Data.ConnectionState.Closed)
            {
                this.Cnx.Close();
            }
        }
 
        public ModelSixDof GetInfoSix()
        {
            ModelSixDof result = new ModelSixDof();
            try
            {
                this.OpenConnection();
                string request = @"SELECT Var1,Var2, Var3,Var4,Var5,Var6
                                    FROM Tab
                                    WHERE  id  = (Select TOP 1 id FROM Tab ORDER BY id Desc)";
 
                this.Cmd = new SqlCommand(request, Cnx);
                SqlDataReader
                Rd = this.Cmd.ExecuteReader();
 
                if (Rd.HasRows)
                {
 
                    Rd.Read();
 
                    result = new ModelSixDof
                    {
                        Var1= Rd.GetFloat(0),
                        Var2= Rd.GetFloat(1),
                        Var3= Rd.GetFloat(2),
                        Var4= Rd.GetFloat(3),
                        Var5= Rd.GetFloat(4),
                        Var6= Rd.GetFloat(5),
 
                    };
                }
                sixval.Clear();
 
                for (int i = 0; i < 5; i++)
                {
                    sixval.Add(Rd.GetFloat(i));
                }
            }
            catch (Exception ex)
            {
                sixval.Clear();
                for (int i = 0; i < 5; i++)
                {
                    sixval.Add(-404);
                }
                result = new ModelSixDof();
            }
            finally
            {
                this.CloseConnection();
            }
            return result;
        }

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
    class ModelSixDof
    {
        public double Var1{ get; set; }
        public double Var2{ get; set; }
        public double Var3{ get; set; }
        public double Var4{ get; set; }
        public double Var5{ get; set; }
        public double Var6{ get; set; }
    }