executing sql statement with a non closed executereader.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: executing sql statement with a non closed executereader.

  1. #1
    Join Date
    Jul 2009
    Posts
    4

    executing sql statement with a non closed executereader.

    hello all,

    i have app that connects to a mysql db.
    i get data from the db with executereader.
    but i want to execute some sql depending on the result from a other db.
    but i get a error when doing ExecuteNonQuery() when the reader is still open.

    what's the best solution for this...

    Here's a part of my code where the problem occures.

    Code:
            tracecom.CommandText = "select * from testsms left join customer on customer.id=testsms.id where date_sub(now(),interval 1 minute) > testsend"
            tracerd = tracecom.ExecuteReader()
            If tracerd.HasRows Then
                While tracerd.Read
                    If tracerd("retries") = 0 Then
                        'first time resend message
                        '****
                        addlog(Now() + " Resent test sms for: " + tracerd("login"))
                        tracecom.CommandText = "UPDATE testsms SET retries=retries+1 Where id=" + CStr(tracerd("id"))
                        tracecom.ExecuteNonQuery()
                    Else
                        'second time offender
                        '**** send owner a message about the fail.
                        addlog(Now() + " Fail on testsms for : " + tracerd("login"))
                        tracecom.CommandText = "UPDATE customer SET lasttestresult=0 Where id=" + CStr(tracerd("id"))
                        tracecom.ExecuteNonQuery()
                        tracecom.CommandText = "DELETE FROM testsms WHERE id=" + CInt(tracerd("id"))
                        tracecom.ExecuteNonQuery()
                    End If
                End While
            End If
    
            tracerd.Close()
    thans

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,961

    Re: executing sql statement with a non closed executereader.

    rd2 or tracecom2 ?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,813

    Re: executing sql statement with a non closed executereader.

    Have you tried using 2 objects? One for the reader and a different one for you updates or whatever sql you want to execute? It seems like the error is likely due to the fact that both your reader and your sql commands are working on the tracecom object.

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: executing sql statement with a non closed executereader.

    As MARS (Multiple Active Resultsets) is not available with MYSQl, you will have to use two different connections to perform an operation while a datareader is open. or else you will first have to close the datareader and then execute another query.

  5. #5
    Join Date
    Jul 2009
    Posts
    4

    Re: executing sql statement with a non closed executereader.

    ok thanks.

    will use a second connection for the updates..
    i was thinking it would be possible within one connection...

    but no prob then..

    thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center