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 / C++ / MFC
  4. The best way to use worker thread to connect to an database

The best way to use worker thread to connect to an database

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabasevisual-studiocomhelp
5 Posts 2 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
    mesajflaviu
    wrote on last edited by
    #1

    What is the best way to connect an database through an worker thread ? I teach from here[^] how to use an worker thread ... Ok , but in worker thread I use theApp global member variable which have an database connection ... but the problem is that not every time thread unconnect database or destroy theApp.m_pDB member variable from CMyApp::ExitInstance() event .... I don't know why ?! So , can you tell me how to connect to an database from an worker thread ? Thank you !

    D 1 Reply Last reply
    0
    • M mesajflaviu

      What is the best way to connect an database through an worker thread ? I teach from here[^] how to use an worker thread ... Ok , but in worker thread I use theApp global member variable which have an database connection ... but the problem is that not every time thread unconnect database or destroy theApp.m_pDB member variable from CMyApp::ExitInstance() event .... I don't know why ?! So , can you tell me how to connect to an database from an worker thread ? Thank you !

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      mesajflaviu wrote:

      So , can you tell me how to connect to an database from an worker thread ?

      I would be inclined to connect to the database in the primary thread, and then pass the CDatabase pointer to the secondary thread.

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "Man who follows car will be exhausted." - Confucius

      M 1 Reply Last reply
      0
      • D David Crow

        mesajflaviu wrote:

        So , can you tell me how to connect to an database from an worker thread ?

        I would be inclined to connect to the database in the primary thread, and then pass the CDatabase pointer to the secondary thread.

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "Man who follows car will be exhausted." - Confucius

        M Offline
        M Offline
        mesajflaviu
        wrote on last edited by
        #3

        Connection to database I make in primary thread ... and now , since I discover threads :D , I try to switch connection to an worker thread ... Ok , I have connection attach it to global theApp variable ... ex : theApp.ExecuteSQL(...) , theApp.GetData(...) , etc. so , you say to pass this varaible ( theApp ) as parameter to worker thread ? Since theApp is global variable , what is the point ?

        D 1 Reply Last reply
        0
        • M mesajflaviu

          Connection to database I make in primary thread ... and now , since I discover threads :D , I try to switch connection to an worker thread ... Ok , I have connection attach it to global theApp variable ... ex : theApp.ExecuteSQL(...) , theApp.GetData(...) , etc. so , you say to pass this varaible ( theApp ) as parameter to worker thread ? Since theApp is global variable , what is the point ?

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          mesajflaviu wrote:

          so , you say to pass this varaible ( theApp ) as parameter to worker thread

          Not what I said at all.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Man who follows car will be exhausted." - Confucius

          M 1 Reply Last reply
          0
          • D David Crow

            mesajflaviu wrote:

            so , you say to pass this varaible ( theApp ) as parameter to worker thread

            Not what I said at all.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "Man who follows car will be exhausted." - Confucius

            M Offline
            M Offline
            mesajflaviu
            wrote on last edited by
            #5

            Then , to pass theApp.m_pDB ( CDatabase* kind of ) like parameter to worker thread ?

            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