Bonjour,
Souhaitant migrer ma base de données MySQL vers une base de données SQL Server (j'ai bien entendu converti ma table à la syntaxe de SQL Server 2012 mais passant)
j'ai donc commencer à retoucher le système de connexion de mon application j'ai remplacé toutes les fonctions de MySQL par celle de SQL Server 2012, hors actuellement je rencontre un soucis, mon application se connecte bien à la base de données SQL Server (yeah)
mais quand celui-ci exécute une requête afin de pouvoir récupérer la totalités des logs de mes membres (cela fais ça sur n'importe quel requête) celui-ci m'affiche l'erreur
"La référence d'objet n'est pas défini à une instance d'un objet " concernant la ligne 22 de mon fichier bdd.cs qui concerne ce bout de code :
Voici mon code complet :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 public void Dispose() { Connection.Close(); Command.Dispose(); Connection.Dispose(); }
Je ne comprend pas trop comment régler ce soucis donc si vous pouviez m'éclairer ou m'aider à déboguer mon code.. afin qu'il exécute les requête..
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 internal sealed class DatabaseClient : IDisposable { private DatabaseManager Manager; private SqlCommand Command; private SqlConnection Connection; public DatabaseClient(DatabaseManager _Manager) { Manager = _Manager; SqlConnection Connection = new SqlConnection(_Manager.ConnectionString); Command = Connection.CreateCommand(); Connection.Open(); } public void Dispose() { Connection.Close(); Command.Dispose(); Connection.Dispose(); } public void AddParamWithValue(string sParam, object val) { Command.Parameters.AddWithValue(sParam, val); } public void ExecuteQuery(string sQuery) { Command.CommandText = sQuery; Command.ExecuteScalar(); Command.CommandText = null; } public DataSet ReadDataSet(string Query) { DataSet dataSet = new DataSet(); Command.CommandText = Query; using (SqlDataAdapter SqlDataAdapter = new SqlDataAdapter(this.Command.ToString(), Connection)) // using (MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter(this.Command)) { SqlDataAdapter.Fill(dataSet); } Command.CommandText = null; return dataSet; } public DataTable ReadDataTable(string Query) { DataTable dataTable = new DataTable(); Command.CommandText = Query; using (SqlDataAdapter SqlDataAdapter = new SqlDataAdapter(this.Command.ToString(), Connection)) { SqlDataAdapter.Fill(dataTable); } Command.CommandText = null; return dataTable; } public DataRow ReadDataRow(string Query) { DataTable dataTable = this.ReadDataTable(Query); if (dataTable != null && dataTable.Rows.Count > 0) { return dataTable.Rows[0]; } return null; } public string ReadString(string Query) { Command.CommandText = Query; string result = this.Command.ExecuteScalar().ToString(); Command.CommandText = null; return result; } public int ReadInt32(string Query) { Command.CommandText = Query; int result = int.Parse(this.Command.ExecuteScalar().ToString()); Command.CommandText = null; return result; } public uint ReadUInt32(string Query) { Command.CommandText = Query; uint result = (uint)this.Command.ExecuteScalar(); Command.CommandText = null; return result; } }
Partager