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



  • 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
    

    @



  • 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.



  • 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()...



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.