2

I have a local MSSQL database with several users. I use server authentication in Management Studio successfully, but when I try to connect the database in QT it uses local windows username instead of the one I provided.

Code:

db.setDatabaseName("DRIVER={SQL Server};SERVER={8SQLQT};DATABASE=GradingSystem;Trusted_Connection=yes;");
db.setUserName("ivanov");
db.setPassword("1");
db.open(); 
qDebug() << db.userName() << db.lastError();

Debug output:

"ivanov" QSqlError("18456", "QODBC3: Unable to connect", "[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '8sqlqt\asdfgh'.")

asdfgh is a name of local windows user.

4

1 回答 1

1

你试过这个吗?

db.setDatabaseName("DRIVER={SQL Server};SERVER={8SQLQT};DATABASE=GradingSystem;Trusted_Connection=no;user_id=ivanov;password=1;");
db.open();
qDebug() << db.userName() << db.lastError();
于 2015-08-20T08:45:51.890 回答