简体   繁体   中英

debug pdo connection username when windows authentication logon used

I tried new connection via:

$conn = new PDO("sqlsrv:server=SERVERNAME;database=DBNAME;MultipleActiveResultSets=false", "username", "password");

and it did not work, however when I remove the username and password it works fine. username is the same as my windows login, I tried multiple combinations as DOMAIN\\username or username@domain.com etc, nothing works. However when username and password are not present, then it connects fine.

The error is:

SQLSTATE[28000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user 'username'.

so to my question, in order to debug the problem. Is it possible to check what username is used when automatic authentication is used after the login succeed?

EDIT: so once upon login without username and pass i tried:

Select name FROM DBNAME.sys.syslogins

and it gave me "DOMAIN\\USERNAME"

I have tried that several times even before, but still same error :(

EDIT2: is it in db loginlist authorization? I have tried SQL Studio to log in via Windows authentication - works fine, however when i sqich to SQL server authentication and use the correct username and password, it gives me same error again, like the username is not existing anymore...

So at the end, I have found out that one account can not be set to log in via SQL authentication and windows authentication as well. So If I can login via windows authentication (no username and pass entered), then only way is to create new account with same username and set it as SQL Authentication upon Login. Please correct me if Im wrong (and mainly someone who can test otherwise - because i have found security setting to the account which says "SQL Server and Windows Authentication mode" which is active anyway but doesnt work, and according to our database admin, this setting is not what its for)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM