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. How to make a Windows service to manage SQLite DB

How to make a Windows service to manage SQLite DB

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpsqlitesysadminlinux
14 Posts 4 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.
  • L Lost User

    Sorry but that information does not give any clues. I can only suggest you add some more debugging logic to your service program to see what is happening.

    I Offline
    I Offline
    intelstar venus
    wrote on last edited by
    #5

    Can I make debugging on the running service? And I'm using VS2015 but service debugging is seen somewhat different with normal application. Please teach me how to debug service program. :((

    L 1 Reply Last reply
    0
    • I intelstar venus

      Can I make debugging on the running service? And I'm using VS2015 but service debugging is seen somewhat different with normal application. Please teach me how to debug service program. :((

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #6

      Member 11967800 wrote:

      Please teach me how to debug service program.

      See https://msdn.microsoft.com/en-us/library/7a50syb3(v=vs.110).aspx[^].

      I 1 Reply Last reply
      0
      • L Lost User

        Member 11967800 wrote:

        Please teach me how to debug service program.

        See https://msdn.microsoft.com/en-us/library/7a50syb3(v=vs.110).aspx[^].

        I Offline
        I Offline
        intelstar venus
        wrote on last edited by
        #7

        Thank you for your kindly advice. But my vaccine 365 security reject it as a virus. But www.virustotal.com doesn't report it as a virus. I also have no clue on it, maybe the vaccine detects the approach to the registry by debug mode built service. Now I'm using Error log file and monitor its action. Please check this function and give me your precious advice. DALConnection::ExecutionResult SQLiteRecordset::TryOpen(std::shared_ptr pDALConn, const SQLCommand &command, String &sErrorMessage) { String sSQL = command.GetQueryString(); try { std::shared_ptr pConn = std::static_pointer_cast (pDALConn); std::shared_ptr dbengin_ = pConn->GetConnection(); AnsiString sQuery; if (!Unicode::WideToMultiByte(sSQL, sQuery)) { ErrorManager::Instance()->ReportError(ErrorManager::Critical, 5108, "SQLiteRecordset::TryOpen", "Could not convert string into multi-byte."); return DALConnection::DALUnknown; } record_cnt_ = cur_row_ = 0; field_list_.clear(); value_list_.clear(); ErrorManager::Instance()->ReportError(ErrorManager::High, 3156, "SQLiteRecordset::TryOpen", sQuery); /* sQuery = "select * from my_settings"; If I set this value like this, SQL query will be succeed, but only using sQuery normally will be failed. Simple query such as "select * from my_dbversion" will be succeed but large data querying will be failed. I don't know the clue. */ SQLite3QueryCpp query_ = dbengin_->execQuery(sQuery); int numFld = query_.numFields(); String data = "\n"; for (int i = 0; i < numFld; i++) { field_list_.push_back(query_.fieldName(i)); data += query_.fieldName(i); data += "\t"; } data += "\n"; while (!query_.eof()) { std::vector sRow; for (int i = 0; i < numFld; i++){ sRow.push_back(query_.fieldValue(i)); data += query_.fieldValue(i); data += "\t"; } data += "\n"; value_list_.push_back(sRow); record_cnt_++; query_.nextRow(); } query_.finalize(); ErrorManager::Instance()->ReportError(ErrorManager::High, 3156, "SQLiteRecordset::TryOpen ...", data); } catch (...) { ErrorManager::Instance()->ReportError(ErrorManager::High, 4202, "SQLiteRecordset::TryOpen", "An unknown error occurred while executing " + sSQL); return DALConnection::DALErrorInSQL; } return DALConnectio

        L D 2 Replies Last reply
        0
        • I intelstar venus

          Thank you for your kindly advice. But my vaccine 365 security reject it as a virus. But www.virustotal.com doesn't report it as a virus. I also have no clue on it, maybe the vaccine detects the approach to the registry by debug mode built service. Now I'm using Error log file and monitor its action. Please check this function and give me your precious advice. DALConnection::ExecutionResult SQLiteRecordset::TryOpen(std::shared_ptr pDALConn, const SQLCommand &command, String &sErrorMessage) { String sSQL = command.GetQueryString(); try { std::shared_ptr pConn = std::static_pointer_cast (pDALConn); std::shared_ptr dbengin_ = pConn->GetConnection(); AnsiString sQuery; if (!Unicode::WideToMultiByte(sSQL, sQuery)) { ErrorManager::Instance()->ReportError(ErrorManager::Critical, 5108, "SQLiteRecordset::TryOpen", "Could not convert string into multi-byte."); return DALConnection::DALUnknown; } record_cnt_ = cur_row_ = 0; field_list_.clear(); value_list_.clear(); ErrorManager::Instance()->ReportError(ErrorManager::High, 3156, "SQLiteRecordset::TryOpen", sQuery); /* sQuery = "select * from my_settings"; If I set this value like this, SQL query will be succeed, but only using sQuery normally will be failed. Simple query such as "select * from my_dbversion" will be succeed but large data querying will be failed. I don't know the clue. */ SQLite3QueryCpp query_ = dbengin_->execQuery(sQuery); int numFld = query_.numFields(); String data = "\n"; for (int i = 0; i < numFld; i++) { field_list_.push_back(query_.fieldName(i)); data += query_.fieldName(i); data += "\t"; } data += "\n"; while (!query_.eof()) { std::vector sRow; for (int i = 0; i < numFld; i++){ sRow.push_back(query_.fieldValue(i)); data += query_.fieldValue(i); data += "\t"; } data += "\n"; value_list_.push_back(sRow); record_cnt_++; query_.nextRow(); } query_.finalize(); ErrorManager::Instance()->ReportError(ErrorManager::High, 3156, "SQLiteRecordset::TryOpen ...", data); } catch (...) { ErrorManager::Instance()->ReportError(ErrorManager::High, 4202, "SQLiteRecordset::TryOpen", "An unknown error occurred while executing " + sSQL); return DALConnection::DALErrorInSQL; } return DALConnectio

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #8

          Sorry, but I cannot figure what is going on here, or what is supposed to be going on. Which of the log messages actually identifies any error?

          I 1 Reply Last reply
          0
          • L Lost User

            Sorry, but I cannot figure what is going on here, or what is supposed to be going on. Which of the log messages actually identifies any error?

            I Offline
            I Offline
            intelstar venus
            wrote on last edited by
            #9

            "select * from hm_dbversion" reports correct result. but next "select * from hm_settings" report nothing. If we change sQuery = "select * from hm_settings" directly, it reports proper result. But it actually useless in practice, and i need to process the dynamical SQL commands in the service. I can't find the reason and crashed with a barrier. Now I have a doubt in the timing of SQL commands. I'm so sorry for your efforts, best regards!

            1 Reply Last reply
            0
            • I intelstar venus

              Thank you for your kindly advice. But my vaccine 365 security reject it as a virus. But www.virustotal.com doesn't report it as a virus. I also have no clue on it, maybe the vaccine detects the approach to the registry by debug mode built service. Now I'm using Error log file and monitor its action. Please check this function and give me your precious advice. DALConnection::ExecutionResult SQLiteRecordset::TryOpen(std::shared_ptr pDALConn, const SQLCommand &command, String &sErrorMessage) { String sSQL = command.GetQueryString(); try { std::shared_ptr pConn = std::static_pointer_cast (pDALConn); std::shared_ptr dbengin_ = pConn->GetConnection(); AnsiString sQuery; if (!Unicode::WideToMultiByte(sSQL, sQuery)) { ErrorManager::Instance()->ReportError(ErrorManager::Critical, 5108, "SQLiteRecordset::TryOpen", "Could not convert string into multi-byte."); return DALConnection::DALUnknown; } record_cnt_ = cur_row_ = 0; field_list_.clear(); value_list_.clear(); ErrorManager::Instance()->ReportError(ErrorManager::High, 3156, "SQLiteRecordset::TryOpen", sQuery); /* sQuery = "select * from my_settings"; If I set this value like this, SQL query will be succeed, but only using sQuery normally will be failed. Simple query such as "select * from my_dbversion" will be succeed but large data querying will be failed. I don't know the clue. */ SQLite3QueryCpp query_ = dbengin_->execQuery(sQuery); int numFld = query_.numFields(); String data = "\n"; for (int i = 0; i < numFld; i++) { field_list_.push_back(query_.fieldName(i)); data += query_.fieldName(i); data += "\t"; } data += "\n"; while (!query_.eof()) { std::vector sRow; for (int i = 0; i < numFld; i++){ sRow.push_back(query_.fieldValue(i)); data += query_.fieldValue(i); data += "\t"; } data += "\n"; value_list_.push_back(sRow); record_cnt_++; query_.nextRow(); } query_.finalize(); ErrorManager::Instance()->ReportError(ErrorManager::High, 3156, "SQLiteRecordset::TryOpen ...", data); } catch (...) { ErrorManager::Instance()->ReportError(ErrorManager::High, 4202, "SQLiteRecordset::TryOpen", "An unknown error occurred while executing " + sSQL); return DALConnection::DALErrorInSQL; } return DALConnectio

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

              I see references to my_settings and hm_settings, as well as hm_dbversion and my_dbversion? Are these intentional?

              "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

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              I 1 Reply Last reply
              0
              • D David Crow

                I see references to my_settings and hm_settings, as well as hm_dbversion and my_dbversion? Are these intentional?

                "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

                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                I Offline
                I Offline
                intelstar venus
                wrote on last edited by
                #11

                Sorry, I tried to change it intentionally. The problem was settled. I found that I was so idiot. I had mistaken by using invalid Error Log function. ErrorManager::Instance()->ReportError(ErrorManager::Critical, ...); I'm very sorry to everybody. And very thanks all of you who had offered kind advises. ;)

                1 Reply Last reply
                0
                • I intelstar venus

                  I used CppSQLite3_2.zip freeware and wrote some Windows service to manage SQLite DB. As a simple application, it acts well. ex. In the application for test, this code reported proper value. const char* gszFile = "e:\\Test\\Database\\Server.db3"; int TryOpen(char * sql) { SQLite3DBCpp *db = new SQLite3DBCpp; db->open(gszFile); SQLite3QueryCpp q = db->execQuery("select * from my_settings"); q.finalize(); db->close(); } But after implemented as a service, it doesn't returned any values. ex. in the service program, I used the above code directly. Here I tried to give SQL cmd as a parameter. AnsiString sQuery; ... SQLite3QueryCpp q = db->execQuery(sQuery.c_str()); If I give a static command such as "select * from my_settings" instead of sQuery.c_str(), it operated properly, but it doesn't act when it receives a dynamic params. In fact, if we dumped the sQuery.c_str(), the output was "select * from my_settings". What's the matter? Please tell me the reason. I think it'll be no problem in Linux, but I don't know the Windows inside well. Please help me, Best regards!

                  J Offline
                  J Offline
                  jschell
                  wrote on last edited by
                  #12

                  Just noting that in general a windows service would not be used to "manage" a database. A database might be a windows service (or more than one service.) A management API would exist on one of those servers. Then an application, not service, would use that API and present a interface, like a GUI, to a user. The interface could also be a command line console. A service API that would support the above would support the following 1- A definition of a protocol, such as Rest or more generally http 2- Commands that are sent via the protocol and responses to those commands. 3- The API protocol would be a LAYER on top of the actual management code. 3a - Supporting 3 one should probably add logging. 4- Management layer. At best from your code it looks something like 3. I suggest you look into learning how to use a logging API. Additionally there are other aspects involved with getting a windows service to run, and those have nothing to do with the actual database problem. For example A- Starting/stopping the service B- Running with the correct user

                  Member 11967800 wrote:

                  If I give a static command such as "select * from my_settings" instead of sQuery.c_str(), it operated properly, but it doesn't act when it receives a dynamic params.

                  That doesn't have anything to do with windows service. It has to do with how you implemented the code. At best this looks like 4 above and you should get it that to work BEFORE you attempt to do anything else.

                  I 1 Reply Last reply
                  0
                  • J jschell

                    Just noting that in general a windows service would not be used to "manage" a database. A database might be a windows service (or more than one service.) A management API would exist on one of those servers. Then an application, not service, would use that API and present a interface, like a GUI, to a user. The interface could also be a command line console. A service API that would support the above would support the following 1- A definition of a protocol, such as Rest or more generally http 2- Commands that are sent via the protocol and responses to those commands. 3- The API protocol would be a LAYER on top of the actual management code. 3a - Supporting 3 one should probably add logging. 4- Management layer. At best from your code it looks something like 3. I suggest you look into learning how to use a logging API. Additionally there are other aspects involved with getting a windows service to run, and those have nothing to do with the actual database problem. For example A- Starting/stopping the service B- Running with the correct user

                    Member 11967800 wrote:

                    If I give a static command such as "select * from my_settings" instead of sQuery.c_str(), it operated properly, but it doesn't act when it receives a dynamic params.

                    That doesn't have anything to do with windows service. It has to do with how you implemented the code. At best this looks like 4 above and you should get it that to work BEFORE you attempt to do anything else.

                    I Offline
                    I Offline
                    intelstar venus
                    wrote on last edited by
                    #13

                    Thank you for your kind advice. The problem was in using bad logger function. I misused it and it disturbed normal activity of my SQLiteDB engine. Now everything is OK. Thank you again.

                    J 1 Reply Last reply
                    0
                    • I intelstar venus

                      Thank you for your kind advice. The problem was in using bad logger function. I misused it and it disturbed normal activity of my SQLiteDB engine. Now everything is OK. Thank you again.

                      J Offline
                      J Offline
                      jschell
                      wrote on last edited by
                      #14

                      intelstar venus wrote:

                      The problem was in using bad logger function.

                      In general that should never happen. A good logger should not normally impact an application if the logger fails.

                      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