Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Running SQL in a Thread

Running SQL in a Thread

Scheduled Pinned Locked Moved C#
databasewinformsquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MarkMokris
    wrote on last edited by
    #1

    I have a Windows Forms app in which I execute a SQL statement using SQLDataAdapter. I want the user to be able to kill the SQL statement if it seems to take to long. My thought is to execute the SQL in its own thread. Then when the user clicks a Cancel button it just stops the Thread. Is this the best way to do this? Will it work? Is is inefficient? Thanks, Mark Mokris

    L L 2 Replies Last reply
    0
    • M MarkMokris

      I have a Windows Forms app in which I execute a SQL statement using SQLDataAdapter. I want the user to be able to kill the SQL statement if it seems to take to long. My thought is to execute the SQL in its own thread. Then when the user clicks a Cancel button it just stops the Thread. Is this the best way to do this? Will it work? Is is inefficient? Thanks, Mark Mokris

      L Offline
      L Offline
      Le centriste
      wrote on last edited by
      #2

      Use the SqlDataAdapter in a thread, as you suggested, but I would add a twist. Instead of calling Thread.Abort() to terminate the thread, have your thread read small chunks of data at a time, and check for a flag telling it to stop between reads. Doing it this way, you could even have a progress bar in your main window showing the progress to the user. -------- "I say no to drugs, but they don't listen." - Marilyn Manson

      1 Reply Last reply
      0
      • M MarkMokris

        I have a Windows Forms app in which I execute a SQL statement using SQLDataAdapter. I want the user to be able to kill the SQL statement if it seems to take to long. My thought is to execute the SQL in its own thread. Then when the user clicks a Cancel button it just stops the Thread. Is this the best way to do this? Will it work? Is is inefficient? Thanks, Mark Mokris

        L Offline
        L Offline
        LighthouseJ
        wrote on last edited by
        #3

        As someone suggested to me on here yesterday, you might want to look into System.ComponentModel.BackgroundWorker as an alternative. I haven't used it myself, I stuck to threads because it's what I know much more of anyway but it might be worth looking into yourself.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups