Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. SQL connect to port, which is not opened...
Qt 6.11 is out! See what's new in the release blog

SQL connect to port, which is not opened...

Scheduled Pinned Locked Moved Language Bindings
4 Posts 2 Posters 3.6k 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.
  • P Offline
    P Offline
    Peppy
    wrote on last edited by
    #1

    Well, here I am...again... I have got this issue:
    I am connected to IP (localhost) with a specific port, let it be 33054 (on Linux). Although I am connecting to port 33054, which is closed, it connect to it!...
    Database driver: MySQL, the newest Qt...

    The code:
    @
    class DB:
    tables = {}
    tables['admins'] = "admins"

        userdata = {}
        error_msg, error_code = (None, None)
        database = (None, None)
     
        def __init__(self):
     
            self.db = QSqlDatabase.addDatabase("QMYSQL")
     
            self.db.setUserName("root")
            self.db.setPassword("pwd")
            self.db.setDatabaseName("schp")
     
        def setState(self, code, msg = None):
            """
           Sets result code / error code of last action
           """
     
            self.code = code
            if code == 0:
                self.error_code = None
                self.error_msg = None
            else:
                self.error_code = code
                self.error_msg = msg
     
            return code
       
        #
        # ----------------------------------------------------------------------------------------------
        # DB CONNECT AND LOGIN
        # ----------------------------------------------------------------------------------------------
        #
        def connect(self, server):
            self.db.setHostName(server)
            self.db.setPort(33054)
     
            print self.db.port()
     
            ok = self.db.open()
            print self.db.lastError().databaseText()
            if ok:
                print "Connected to", server
            else:
                print "Error while connecting to the server", server
     
            return ok
    

    @

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      That's because you are accessing to your self ( localhost), and it behaves differently.
      Try connecting via IP, or test your port with telnet.
      If it succeeds, your port is open.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Peppy
        wrote on last edited by
        #3

        No, that port is definitely closed. I have tried to connect also via other IP (192.168.0.11) but it still connects. It looks like QtSql ignores setting port through setPort()...

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Port blocking rules on your router do not apply on your local network and
          DB Manager automatically opens the configured port on your computer.

          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