IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Probleme de datareader et executenonquery


Sujet :

VB.NET

  1. #1
    Membre régulier
    Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2007
    Messages
    81
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Vaucluse (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2007
    Messages : 81
    Points : 79
    Points
    79
    Par défaut Probleme de datareader et executenonquery
    Bonjour,
    Cela fait deux jours que je m'arrache les cheveux pour trouver une solution à mon problème.

    En gros , dams datareader, j'exécute un requête de mise à jour avec executenonquey, et il me met une erreur.
    Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
    Et il met en rouge l'execute reader commande15
    Je voudrais savoir s'il est possible de faire cela.
    Merci de votre aide
    voici mon code
    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
    118
    119
    120
    121
    Dim sConn = ConfigurationManager.ConnectionStrings("SiteConnectionString").ConnectionString.ToString()
        Dim oConn = New SqlConnection(sConn)
        oConn.Open()
        
        Dim i As Integer
        If Request.Form("Choisir") = "Update" Then
            ' création des csv
            For i = 1 To Request.Form("NbrPart")
                ' on va récuperer le nom du partenaire
                Dim Mycommand8 As SqlCommand = oConn.CreateCommand()
                Mycommand8.CommandText = "select * FROM Partenaire where NumAuto=" & Request.Form("Partenaire" & i)
                Dim RsPart2 As SqlDataReader = Mycommand8.ExecuteReader()
                RsPart2.Read()
    
                Dim NomPartenaire As String = RsPart2("IdPartenaire")
                Dim email As String = RsPart2("Email")
                Dim CodeAgencePartenaire As String = RsPart2("CodeAgencePartenaire")
                Dim CodeAgenceInterne As String = RsPart2("CodeAgenceInterne")
                Dim AdresseFtp As String = RsPart2("AdresseFtp")
                Dim UtilFtp As String = RsPart2("UtilFtp")
                Dim MotPasseFtp As String = RsPart2("MotPasseFtp")
                Dim FormatFichier As String= RsPart2("FormatFichier")
                Dim NumAutoPartenaire As String = RsPart2("NumAuto")
               
                Dim fs As FileStream
                Dim sw As StreamWriter
            ......
                
                ' écriture du xml
                sw.WriteLine("<?xml version=""1.0"" encoding=""utf-8""?>")
                '		sw.WriteLine(" <!DOCTYPE xsl:stylesheet [<!ENTITY nbsp   "" "">")
             
                ' ecriture informations contenues dans les annonces
                ' on va parcourir les annonces et voir si elle sont cochées
                Dim Mycommand9 As SqlCommand = oConn.CreateCommand()
                Mycommand9.CommandText = "select * FROM annonce order by titre asc"
                Dim Mycommand15 As SqlCommand = oConn.CreateCommand()
                Dim Mycommand10 As SqlCommand = oConn.CreateCommand()
                Dim RsAnnonces2 As SqlDataReader = Mycommand9.ExecuteReader()
                While RsAnnonces2.Read()
                    If Request.Form("Partenaire_" & i & "_" & RsAnnonces2("numauto")) = "ok" Then ' on verifie si le partenaire a bien été coché
                        ' on cohe la case
                       
                        Mycommand10.CommandText = "Update Annonce set CaseCoche" & NumAutoPartenaire & "=1 where numauto=" & RsAnnonces2("NumAuto")
                        'Mycommand10.ExecuteNonQuery()
                        'Response.Write("Update Annonce set CaseCoche" & NumAutoPartenaire & "=-1 where numauto=" & RsAnnonces2("NumAuto"))
                        'response.write sqlUpdate
                        sw.WriteLine("<Annonce>")
                        sw.WriteLine("<Reference>" & RsAnnonces2("reference") & "</Reference> ")
                        'Création des champs titres du fichier CSV
                        ' on recupere le type
                        Dim Mycommand11 As SqlCommand = oConn.CreateCommand()
                        Mycommand11.CommandText = "select * FROM type where numauto=" & RsAnnonces2("fk_type")
                        Dim RsType2 As SqlDataReader = Mycommand11.ExecuteReader()
                        RsType2.Read()
                        Dim typeAnnonce As String = RsType2("titre")
                        ' la categorie
                        
                        Dim Mycommand12 As SqlCommand = oConn.CreateCommand()
                        Mycommand12.CommandText = "select * FROM Categorie where numauto=" & RsAnnonces2("fk_cat")
                        Dim RsCat2 As SqlDataReader = Mycommand12.ExecuteReader()
                        RsCat2.Read()
                     
                        Dim cat As String = RsCat2("titre")
                        'recup du secteur
                        
                        Dim Mycommand13 As SqlCommand = oConn.CreateCommand()
                        Mycommand13.CommandText = "select * FROM secteur where numauto=" & RsAnnonces2("fk_secteur")
                        Dim RsSecteur2 As SqlDataReader = Mycommand13.ExecuteReader()
                        RsSecteur2.Read()
                        
                        Dim secteur As String = RsSecteur2("titre")
                        Dim CodePostal As String = RsSecteur2("CodePostal")
                        
                        Dim descriptif As String = Replace(RsAnnonces2("descriptif"), "<DIV id=menu>", " ")
                        descriptif = Replace(descriptif, "</DIV>", " ")
                        descriptif = Replace(descriptif, "<DIV>", " ")
                        descriptif = Replace(descriptif, "<P class=MsoNormal style=""MARGIN: 0cm 0cm 0pt"">", " <P>")
                        descriptif = Replace(descriptif, "<SPAN style=""FONT-SIZE: 9pt; FONT-FAMILY: Arial"">", " ")
                        descriptif = Replace(descriptif, "</SPAN>", " ")
                        descriptif = Replace(descriptif, "<BR>", " ")
                        descriptif = Replace(descriptif, "<BR />", " ")
                        sw.WriteLine("<TypeBien>" & cat & "</TypeBien>")
                        sw.WriteLine("<Rubrique>" & typeAnnonce & "</Rubrique>")
                        sw.WriteLine("<DateCreation>" & RsAnnonces2("DateCreation") & "</DateCreation>")
                        sw.WriteLine("<DateModification>" & RsAnnonces2("DateModif") & "</DateModification> ")
                        sw.WriteLine("<CodePostal>" & CodePostal & "</CodePostal>")
                        sw.WriteLine("<Ville>" & secteur & "</Ville>")
                        sw.WriteLine("<Titre>" & RsAnnonces2("titre") & "</Titre> ")
                        sw.WriteLine("<Texte> <![CDATA[" & Trim(descriptif) & "]]></Texte> ")
                        sw.WriteLine("<Prix>" & RsAnnonces2("prix") & " Euros</Prix>")
                        If RsAnnonces2("Honoraire") <> 0 Then
                            sw.WriteLine("<Honoraires>" & RsAnnonces2("Honoraire") & "</Honoraires>")
                        End If
                        sw.WriteLine("<NbPieces>" & RsAnnonces2("NbrPiece") & "</NbPieces>")
    		
                        Dim Mycommand14 As SqlCommand = oConn.CreateCommand()
                        Mycommand14.CommandText = "select * FROM Photos where reference='" & RsAnnonces2("reference") & "'"
                        Dim RsPhoto As SqlDataReader = Mycommand14.ExecuteReader()
                        RsPhoto.Read()
                      
                        Dim nbrPhoto As Integer = 0
                        While RsPhoto.Read
                           
                            sw.WriteLine("<URL_Photo> " & RsPhoto("photo") & "</URL_Photo>")
                            nbrPhoto = nbrPhoto + 1
    
                        End While
                        sw.WriteLine("</Annonce>")
                    Else
                         'Mycommand15.CommandTimeout = 5000
                        Dim CaseCoche As String
                        CaseCoche = "CaseCoche" & NumAutoPartenaire
                        Mycommand15.CommandText = "Update Annonce set " & CaseCoche & "=0 where NumAuto=" & RsAnnonces2("NumAuto")
                        Mycommand15.ExecuteNonQuery()
                        Mycommand15.Dispose()
                        Mycommand15 = Nothing
                       
                        Response.Write("Update Annonce set CaseCoche" & NumAutoPartenaire & "=0 where NumAuto=" & RsAnnonces2("NumAuto"))
                    End If

  2. #2
    Responsable .NET

    Avatar de Hinault Romaric
    Homme Profil pro
    Consultant
    Inscrit en
    Janvier 2007
    Messages
    4 570
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Consultant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2007
    Messages : 4 570
    Points : 252 372
    Points
    252 372
    Billets dans le blog
    121
    Par défaut
    Le problème est au niveau du command Time Out faudra juste augmenter sa valeur puisque ta requête de mise a jour prend trop de temps.
    Vous souhaitez participer aux rubriques .NET ? Contactez-moi

    Si déboguer est l’art de corriger les bugs, alors programmer est l’art d’en faire
    Mon blog, Mes articles, Me suivre sur Twitter
    En posant correctement votre problème, on trouve la moitié de la solution

  3. #3
    Membre régulier
    Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2007
    Messages
    81
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Vaucluse (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2007
    Messages : 81
    Points : 79
    Points
    79
    Par défaut
    Mais tu crois que c'est suffisant, j'ai pas une erreur dans mon code??
    Car même en mettant un grand timeout, il ne fait rien. Je ne pense pas que ça soit ma solution.
    Merci de ton aide

  4. #4
    Membre régulier
    Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2007
    Messages
    81
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Vaucluse (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2007
    Messages : 81
    Points : 79
    Points
    79
    Par défaut
    J'ai également cette erreur
    La transaction (ID de processus 56) a été bloquée sur les ressources verrou | objet générique pouvant être attendu par un autre processus et a été choisie comme victime

  5. #5
    Membre régulier
    Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2007
    Messages
    81
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Vaucluse (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2007
    Messages : 81
    Points : 79
    Points
    79
    Par défaut
    J'ai trouvé la solution. Sql server verrouille ma table, donc je ne peux pas faire de modification dessus( alors qu'en access c'est possible, d'où mon entêtement).
    J'ai donc créer un tableau à deux dimensions qui stockent mes données, je les traite une fois mon datareader fermé.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 9
    Dernier message: 21/04/2011, 19h44
  2. probleme avec DataReader
    Par yassin123441 dans le forum C#
    Réponses: 8
    Dernier message: 21/04/2011, 15h55
  3. Probleme dataReader et as400
    Par sisier dans le forum VB.NET
    Réponses: 1
    Dernier message: 07/02/2011, 17h01
  4. Probleme DataReader methode Authentififcation.
    Par lolymeupy dans le forum ASP.NET
    Réponses: 2
    Dernier message: 14/08/2007, 11h59
  5. Probleme avec un Datareader
    Par Quorthon dans le forum ASP.NET
    Réponses: 2
    Dernier message: 23/02/2007, 14h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo