First, the string built by this:
	
	- "DRIVER={SQL Server};SERVER='"+server+"';DATABASE='"+database+"';UID='"+username+"';PWD='"+pass+"';Trusted_Connection=Yes" 
- // "DRIVER={SQL Server};SERVER='localhost';DATABASE='mydatabase';UID='sa';PWD='sa';Trusted_Connection=Yes" 
        "DRIVER={SQL Server};SERVER='"+server+"';DATABASE='"+database+"';UID='"+username+"';PWD='"+pass+"';Trusted_Connection=Yes"
// "DRIVER={SQL Server};SERVER='localhost';DATABASE='mydatabase';UID='sa';PWD='sa';Trusted_Connection=Yes"
To copy to clipboard, switch view to plain text mode 
  and the string you used here:
	
	- "DRIVER={SQL Server};SERVER=localhost;DATABASE=mydatabase;UID=sa;PWD=sa;Trusted_Connection=Yes" 
        "DRIVER={SQL Server};SERVER=localhost;DATABASE=mydatabase;UID=sa;PWD=sa;Trusted_Connection=Yes"
To copy to clipboard, switch view to plain text mode 
  are not the same.
Second.  If you are going to build the full connection string then why bother telling Qt the user name, password, host, and database name separately?  
I would would try this:
	
	- db.setDatabaseName("DRIVER={SQL Server};Trusted_Connection=Yes"); 
- db.setDatabaseName(database); 
- db.setPassword(pass); 
- db.setHostName(server); 
- db.setUserName(username); 
- if (db.open()) { 
-  ... 
- } 
        QSqlDatabase db=QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DRIVER={SQL Server};Trusted_Connection=Yes");
db.setDatabaseName(database);
db.setPassword(pass);
db.setHostName(server);
db.setUserName(username);
if (db.open()) {
 ...
}
To copy to clipboard, switch view to plain text mode 
  because it helps you avoid issues with quoting and maintaining horrible connection strings.
Bookmarks