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.

Charlie
  • 197
  • 1
  • 13
  • What happens if you add `Integrated Security=False` into your databaseName string? – tomvodi Aug 20 '15 at 07:56
  • 5
    possible duplicate of [What does Trusted = yes/no mean in Sql connection string?](http://stackoverflow.com/questions/1242993/what-does-trusted-yes-no-mean-in-sql-connection-string) – Helio Aug 20 '15 at 08:20

1 Answers1

1

Have you tried this?

db.setDatabaseName("DRIVER={SQL Server};SERVER={8SQLQT};DATABASE=GradingSystem;Trusted_Connection=no;user_id=ivanov;password=1;");
db.open();
qDebug() << db.userName() << db.lastError();
ramtheconqueror
  • 1,907
  • 1
  • 22
  • 35