I need to connect to two different databases and servers. Right now I can only connect to one database using this code:
def createConnection()
global db
db = QSqlDatabase.addDatabase('QODBC')
db.setDatabaseName('DRIVER={SQL Server};SERVER=%s;DATABASE=%s;UID=%s;PWS=%s;' % (SERVER1, DATABASE1, USERNAME1, PASSWORD1))
if db.open():
print("connected")
return True
else:
print("failed")
return False
Then somewhere in my code I call something like this:
if createConnection():
qry = QSqlQuery(db)
qry.prepare("SELECT * FROM tbl_name")
qry.exec()
while qry.next()
col1 = qry.value("column1")
col2 = qry.value("column2")
Now, I have to connect also to another database that is different: SERVER2, DATABASE2, USERNAME2, PASSWORD2
. How can I do that?