1

I have used the following code for connecting the Microsoft SQL Server's database. but at the time of opening database connection it is throwing an error.

Here is my code,

 from PyQt4.QtGui import * 
 from PyQt4.QtSql import * 
 from PyQt4.QtCore import * 
 import sys

 db = QSqlDatabase.addDatabase("QODBC")
 db.setHostName("DB\DBCENTER2008R2");
 db.setDatabaseName("AU_Test");
 db.setUserName("sa");
 db.setPassword("sa12");
 if (db.open()==False):
     QMessageBox.critical(None, "Database Error",db.lastError().text())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.