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 access remote database server from windows service

How to access remote database server from windows service

Scheduled Pinned Locked Moved C / C++ / MFC
databasesysadminhelptutorialquestion
6 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.
  • Z Offline
    Z Offline
    zhaopi
    wrote on last edited by
    #1

    I have encountered a problem when i try to access database built on a remote server... but when i tried accessing database on my local computer, this problem did not occur... Anybody know how to solve this problem?

    M B 2 Replies Last reply
    0
    • Z zhaopi

      I have encountered a problem when i try to access database built on a remote server... but when i tried accessing database on my local computer, this problem did not occur... Anybody know how to solve this problem?

      M Offline
      M Offline
      Magnus Westin
      wrote on last edited by
      #2

      It would make this question much easier to answer if you could at least post the error you get when you try to access the database. But if I have to guess, I would think that you are using the default service account. That account doesn't have rights to access the network, instead you should create a user with normal user rights, and use that user with your service. Magnus

      Z 2 Replies Last reply
      0
      • Z zhaopi

        I have encountered a problem when i try to access database built on a remote server... but when i tried accessing database on my local computer, this problem did not occur... Anybody know how to solve this problem?

        B Offline
        B Offline
        BambooMoon
        wrote on last edited by
        #3

        From your service running under the system accoun, you can impersonate a user who has permission to access the database: HANDLE token = NULL;j if (LogonUser(szUser, szHostName, szPassword, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &token)) { if (!ImpersonateLoggedOnUser(token)) { CloseHandle(token); token = NULL; } } and then to revert to the system account: if (token) { RevertToSelf(); CloseHandle(token); }

        Z 1 Reply Last reply
        0
        • M Magnus Westin

          It would make this question much easier to answer if you could at least post the error you get when you try to access the database. But if I have to guess, I would think that you are using the default service account. That account doesn't have rights to access the network, instead you should create a user with normal user rights, and use that user with your service. Magnus

          Z Offline
          Z Offline
          zhaopi
          wrote on last edited by
          #4

          But i have used this account in many normal applications(not service) to access the database already, it works fine. Does that mean it should not be because the account does not have the rights to access the network? I will try to add in a normal account, and feedback here~ thanks so much~

          1 Reply Last reply
          0
          • B BambooMoon

            From your service running under the system accoun, you can impersonate a user who has permission to access the database: HANDLE token = NULL;j if (LogonUser(szUser, szHostName, szPassword, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &token)) { if (!ImpersonateLoggedOnUser(token)) { CloseHandle(token); token = NULL; } } and then to revert to the system account: if (token) { RevertToSelf(); CloseHandle(token); }

            Z Offline
            Z Offline
            zhaopi
            wrote on last edited by
            #5

            Sorry,what does this mean? Does that means i need to impersonate an account to have the permission to access the database before connection?

            1 Reply Last reply
            0
            • M Magnus Westin

              It would make this question much easier to answer if you could at least post the error you get when you try to access the database. But if I have to guess, I would think that you are using the default service account. That account doesn't have rights to access the network, instead you should create a user with normal user rights, and use that user with your service. Magnus

              Z Offline
              Z Offline
              zhaopi
              wrote on last edited by
              #6

              And the reason why i did not provide the error message here is because it is a runtime error, no information in detail given!

              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