Forum Discussion
Login failed for user '<token-identified principal>' but works in Data Studio
Hi,
I am trying to use my AD account to connect to the Azure SQL using Java 8, JDBC Driver, and my accessToken.
When I use Data Studio using my AD Account, I can connect successfully to the Azure SQL DB.
But when I use my Java Program then it gives me this error:
Request processing failed; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user '<token-identified principal>'
My code abstract:
SQLServerDataSource ds = new SQLServerDataSource();
ds.setServerName("NAME.database.windows.net");
ds.setDatabaseName("db-name");
ds.setAccessToken(accessToken);
ds.setEncrypt(true);
ds.setTrustServerCertificate(true);
try (Connection connection = ds.getConnection();
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT SUSER_SNAME()")) {
if (rs.next()) {
System.out.println("dbResults => You have successfully logged on as: " + rs.getString(1));
res = rs.getString(1);
}
}
Answer: https://stackoverflow.com/questions/65173552/login-failed-for-user-token-identified-principal-but-works-in-data-studio?noredirect=1#comment115302801_65173552
1 Reply
- rohit00x00Copper Contributor
Answer: https://stackoverflow.com/questions/65173552/login-failed-for-user-token-identified-principal-but-works-in-data-studio?noredirect=1#comment115302801_65173552