Bonjour a tous,
Afin de migrer mon application VB.NET d' ACCESS à SQL SERVER, j'ai utilisé les classes abstraites DbCommand que j'initialise soit en OleDbCommand ou SqlDbCommand à l'aide des Factory
Je rencontre un problème de comportement quand je suis connecté à SQL SERVER comme s'il était impossible d'avoir plusieurs DbCommand en utilisation simultanée :
Petit code pour montrer le problème:
Code VB.NET : 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 Dim Nocde As Integer Dim CNX As DbConnection Dim Cmd, Cmd2 As DbCommand Dim Rdr, Rdr2 As DbDataReader Dim Ville As String Try CNX = TexParam.BASE.Connection 'C'est ma DbConnection initialisée selon la base de donnée (Sqlserver ou OleDbConnection avec Access) Cmd = CNX.CreateCommand() 'Je cree une première DbCommand Cmd.CommandText = "SELECT numero FROM CDE_ENTETES WHERE RefCli='MAUFFREY'" Rdr = Cmd.ExecuteReader() 'Un premier DataReader - super ça marche Nocde = Rdr.GetInt32(0) 'Ok bonne lecture du 1er de mon DataReader Cmd2 = CNX.CreateCommand() 'Je cree une deuxieme DbCommand Cmd2.CommandText = "SELECT ville_f FROM CDE_ENTETES WHERE Numero=" & Nocde.ToString Rdr2 = Cmd2.ExecuteReader() ' et hop PLANTAGE !!! à la première execution --> Un DataReader associé à cette Command est déjà ouvert. Il doit d'abord être fermé. Ville = Rdr.GetString(0) Rdr2.Close() : Rdr2 = Nothing Cmd2.Dispose() : Cmd2 = Nothing Rdr.Close() : Rdr = Nothing Cmd.Dispose() : Cmd = Nothing Catch ex As Exception
Avez vous une idée? une piste à exploiter car je suis vraiment bloqué.
Merci d'avance
Partager