Bonjour tout le monde,

Je suis actuellement entrain d'essayer réaliser une appli qui va chercher des informations sur un serveur mysql 4.0.20a-nt.

J'ai déjà du pas mal chipoter pour enlever l'exception de la version car j'avais installé le connecteur 6.8 alors qu'il me fallait une version antérieur à 6.3 non inclus.

une fois passer l'étape quand je procède à une ouverture de connexion, j'obtiens cette erreur(Only byte lengths of 2, 4, or 8 are supported), alors que l'état de la variable de MysqlConnection est open.

Mais une fois que je fais une lecture sur un reader data, il est vide... je vous mets un peu de code si quelqu'un a une idée car je n'ai pas plus d'indication et je ne vois pas ce que cette exception vient faire à l'ouverture :/.


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
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data.Odbc;
using MySql.Data.MySqlClient;
 
namespace WebService.App_Code.Models.DataBase
{
    class MySQLConnectionDB
    {
        const String dataconnexionMySQL = "SERVER=192.168.***.***; DATABASE=*****; UID=******; PASSWORD=******;";
 
        private MySqlConnection myConnection { get; set; }
 
        public MySQLConnectionDB()
        {
            try
            {
                myConnection = new MySqlConnection(dataconnexionMySQL);
            }
 
            catch (Exception e)
            {
                Console.WriteLine("!!!! ERROR Connection :" + e.Message + " !!!!");
            }
        }
 
        public void openConnection()
        {
            try
            {
                this.myConnection.Open();
            }catch(Exception e){
                Console.WriteLine("!!!! ERROR Connection :" + e.Message + " !!!!");
            }
        }
 
        public void closeConnection()
        {
            this.myConnection.Close();
        }
 
        public MySqlConnection Connection
        {
            get { return myConnection; }
            set { myConnection = value; }
        }
    }
}

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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using MySql.Data.MySqlClient;
 
/*
 *Class qui gère la connection à la BD ansi que la gestion des données entrant et sortant
 */
 
namespace WebService.App_Code.Models.DataBase
{
    class FactoryDBMySql
    {
        private MySQLConnectionDB connectionDB = null;
        private  MySqlCommand sqlCommand = null;
        private MySqlDataReader sqlReader = null;
 
        public FactoryDBMySql()
        {
            this.connectionDB = new MySQLConnectionDB();
        }
 
        public string createNewSqlCommand(String query)
        {
            try
            {
                this.sqlCommand = this.ConnectionDB.Connection.CreateCommand();
                this.sqlCommand.CommandText = query;
                return "OK";
            }
            catch (Exception e)
            {
                Console.WriteLine("!!!! ERREUR SQLCommand : " + e.Message + " !!!!");
                return e.Message;
            }
        }
 
        // Utilisé si la requète contient plus projection
        public string createNewSqlReader()
        {
            if (this.SqlCommand == null) return "NOK";
            try
            {
                this.openConnection();
                this.sqlReader = this.SqlCommand.ExecuteReader();
                return "OK";
            }
            catch (Exception e)
            {
                Console.WriteLine("!!!! ERREUR SQLReader : " + e.Message + " !!!!");
                return e.Message;
            }
        }
 
        public Boolean closesqlReader()
        {
            if (this.sqlReader == null) return true;
            else
            {
                try
                {
                    this.sqlReader.Close();
                    return true;
                }
                catch (Exception e)
                {
                    Console.WriteLine("!!!! ERREUR fermeture SQLReader : " + e.Message + " !!!!");
                    return false;
                }
            }
        }
 
        private MySQLConnectionDB ConnectionDB
        {
            get { return this.connectionDB; }
            set { this.connectionDB = value; }
        }
 
        private void openConnection()
        {
                try
                {
                    this.connectionDB.openConnection();
                }
                catch (Exception e)
                {
                    Console.WriteLine("!!!! ERROR open connection :" + e.Message);
                }
        }
        public void closeConnection()
        {
            try
            {
                this.connectionDB.closeConnection();
            }
            catch (Exception e)
            {
                Console.WriteLine("!!!!  ERROR Closed DB : " + e.Message);
            }
        }
 
        public MySqlDataReader SqlReader
        {
            get { return this.sqlReader; }
            set { this.sqlReader = value; }
        }
 
        public MySqlCommand SqlCommand
        {
            get { return sqlCommand; }
            set { sqlCommand = value; }
        }
    }
}

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
79
80
81
82
83
84
85
86
87
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebService.App_Code.Models.DataBase;
using System.Xml.Serialization;
 
namespace WebService.App_Code.Models.DataBase.Mapping
{
    public class SNRFactory
    {
        public List<SNR> Pannes { get; private set; }
 
        private FactoryDBMySql Factory { get; set; }
 
        private const string queryAll = "SELECT SNR.id,SNR.snr_date,SNR.zone, N.commune, N.secteur, N.site "
            + " FROM stat_snr AS SNR "
            + " LEFT JOIN secteur_name AS N ON SNR.zone LIKE(CONCAT(\"\", N.secteur, \"%\")) "
            + " WHERE DATE_ADD(NOW(), INTERVAL -60 MINUTE) <= SNR.snr_date "
            + " ORDER BY SNR.snr_date DESC;";
 
        public SNRFactory()
        {
            this.Factory = new FactoryDBMySql();
            this.Pannes = new List<SNR>();
        }
 
        public string getAll()
        {
            try
            {
 
                string query = queryAll;
 
                this.Factory.createNewSqlCommand(query);
                string flag = this.Factory.createNewSqlReader();
                if (!flag.Contains("OK")) return flag;
                Pannes = new List<SNR>();
 
 
 
                while (this.Factory.SqlReader.Read())
                {
                    SNR snr = new SNR();
 
                    if (!this.Factory.SqlReader.GetValue(0).GetType().Equals("System.DBNull"))
                    {
                        snr.Id = this.Factory.SqlReader.GetString(0);
                    }
                    else return "2";
 
                    if (!this.Factory.SqlReader.GetValue(1).GetType().Equals("System.DBNull"))
                    {
                        snr.Date = this.Factory.SqlReader.GetString(1);
                    }
 
                    if (this.Factory.SqlReader.GetValue(2).GetType().ToString().Equals("System.String"))
                    {
                        snr.Zone = (string)this.Factory.SqlReader.GetValue(2);
                    }
                    if (this.Factory.SqlReader.GetValue(3).GetType().ToString().Equals("System.String"))
                    {
                        snr.Commune = (string)this.Factory.SqlReader.GetValue(3);
                    }
                    if (this.Factory.SqlReader.GetValue(4).GetType().ToString().Equals("System.String"))
                    {
                        snr.Secteur = (string)this.Factory.SqlReader.GetValue(4);
                    }
                    if (this.Factory.SqlReader.GetValue(5).GetType().ToString().Equals("System.String"))
                    {
                        snr.Site = (string)this.Factory.SqlReader.GetValue(5);
                    }
                    this.Pannes.Add(snr);
 
                }
                this.Factory.closesqlReader();
                this.Factory.closeConnection();
                return "0";
            }
            catch (Exception e)
            {
                return "" + e;
            }
        }
}
}

Voilà le bout principal. La commande SQL a déjà été testé, je sais joindre sans souci la machine et le port 3306.

Merci de votre aide.

Maintenant le fait que je n'obtiens rien dans le readerdata est peu être causé par autre chose que cettte exception...

Cordialement,