Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Connect to a database from inside or outside the network.
Forum Updated to NodeBB v4.3 + New Features

Connect to a database from inside or outside the network.

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 8.5k 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.
  • G Offline
    G Offline
    goetz
    wrote on last edited by
    #2

    To solve this problem, you should ask your IT admins to set up a proper internal DNS that resolves to the correct IP addresses.

    In order to circumvent the problem in the time being: Do a check on application startup and save the hostname that works in a variable. In your case, the check is done every time you try to open the database. There's no need to check over and over again.

    PS:
    To speed up things even further, you can store the hostname in the preferences, using [[Doc:QSettings]]. This is only useful, if you do not have your computer moving inside and outside the network (e.g. a laptop), though.

    http://www.catb.org/~esr/faqs/smart-questions.html

    1 Reply Last reply
    0
    • B Offline
      B Offline
      BonRouge
      wrote on last edited by
      #3

      Thanks for the reply.

      Unfortunately, the 'IT admins' is me. (We're a small company). If you could point me to a way of doing that - setting up a proper internal DNS that resolves to the correct IP addresses - I'd appreciate it.

      Your suggestion of saving the 'good' hostname as a variable sounds good right now. I'm a bit of a beginner with Qt though, so I'm not sure how to set a variable that will persist. Again, if you could point me to that, I'd appreciate it.

      The QSettings idea wouldn't work so well for me because about half of the computers that will be using the application laptops moving in and out of the network.

      Thanks for your help.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #4

        For the DNS: setup a second name server that is used internally only. This one would deliver the private IPs for the names.

        Setting that variable is nothing Qt special, it seems that you're in need of some C++ introduction.

        Anyways, just add a QString to your main class. I'm sorry I can't give you a more detailed advice, because I don't know the overall design of your application.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BonRouge
          wrote on last edited by
          #5

          You're right about needing a C++ introduction. I have read things, but the best way for me to learn it is to do it, so that's what I'm doing.

          I'll see what I can do about both of these issues.

          Thanks for your help.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #6

            You're welcome. The wiki and some older threads have pointers to good introductions to C++ in general and Qt. And of course feel free to ask questions here. We do have a dedicated "C++ Gurus forum":http://developer.qt.nokia.com/forums/viewforum/36/ too, that's for the C++ questions that are not directly Qt related.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fluca1978
              wrote on last edited by
              #7

              If you don't want to set-up a full DNS just place the internal ip in the hosts file of your computer when you are within the local network. Then your application will be able to connect always using the domain name of your server. When you are outside the network, comment out such line.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                BonRouge
                wrote on last edited by
                #8

                Yes, I'd seen that solution, but there are about 6 machines that come and go every day. I can't ask people to keep changing their host file. Good news - I've found some good software called "Simple DNS Plus" which seems to do the job. The only problem with this is that I'm using no-ip because I have a dynamic address. When my address changes, I'll need to update the configuration of Simple DNS Plus. In theory, I should be able to do this in a similar way to how no-ip works. If I can run a service that checks my external IP address and updates the config file of the software, I should be OK. I'm having problems now trying to use QHostInfo to get the IP address associated with my domain name. If you have any pointers there, that would be appreciated.

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  fluca1978
                  wrote on last edited by
                  #9

                  It seems to me that you are implementing a solution that is much more complex than fixing the problem (i.e., placing a DNS system that works). Anyway, depending on the system you are using (unix? linux? windows? mac?) it should not be difficult to make a script that changes your machine configuration to connect to the database. I will not change the application configuration.

                  By the way, a good and quick solution could be to enable port forwarding on the LAN side of your gateway (local network) so that connecting to a certain port will redirect to the database machine. The same on the external side will give you a stable configuration.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #10

                    Just setup a DNS server that is only used internally and delivers the internal, private IPs (eg. 192.168.x.x). This one works independently from the DNS that serves the rest of the world. Your internal DNS would forward everything else than your internal names to another name server. That's a reliable solution which is easy to setup and does not need any dynamic updates.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      BonRouge
                      wrote on last edited by
                      #11

                      Thank you both for your input.

                      I did lots of reading and testing of different DNS servers, and to be honest, a lot of it went over my head. The 'Simple' in the name of this one I'm trying to use was quite attractive.

                      I realise that I could simply ask our staff to use 192.168.x.x to see the site inside the network, and I could use Volker's earlier idea of using a variable in the application to connect to the database at the right address - internal IP or domain name. I could do that, but I think it would confuse people. Maybe that's not a good reason though.

                      Both of your ideas on how to fix this easily sound good, but I'm really not sure how I would actually implement them. Sorry to sound a bit useless.

                      Right now I'm thinking that I might stick with my plan of updating the configuration file of the DNS server when the dynamic IP changes. I realised I can move the config file to somewhere within the web server, change the file with PHP (which I have a lot of experience with) and update the server by a command line command. (It's Windows by the way).

                      I would love to do this a simple way, but as I said, I'm not really understanding the simple way.

                      Thanks for your help.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved