Repository navigation
Description
For any two (or more) connection strings that connect to a Microsoft Azure SQL instance using Authentication=ActiveDirectoryInteractive; where the only difference between them is the User ID value (User ID=user1; vs User ID=User2;) then only the first user is allowed to connect. The second will loop through this UI forever, that is unless you click back and select User1.
User 2 trying to authenticate, click on User 2

User 2 stuck in a loop, click Next brings you back here

To reproduce
using System;
using Microsoft.Data.SqlClient;
private static string USER_1 = "[email protected]";
private static string USER_2 = "[email protected]";
private static string SERVER = "*********.database.windows.net";
private static string DATABASE = "*****";
void Main(string[] args)
{
TestConnection(USER_1);
TestConnection(USER_2);
}
private void TestConnection(string username)
{
using (SqlConnection conn = new SqlConnection(GetConnectionString(SERVER, DATABASE, username)))
{
conn.Open();
SqlCommand command = new SqlCommand("SELECT SUSER_NAME();", conn);
Console.WriteLine(command.ExecuteScalar());
}
}
private static string GetConnectionString(string server, string database, string user)
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder["Data Source"] = server;
builder["Initial Catalog"] = database;
builder.UserID = user;
builder.Authentication = SqlAuthenticationMethod.ActiveDirectoryInteractive;
string result = builder.ConnectionString.ToString();
Console.WriteLine(result);
return result;
}Output for the second user I passed in my privileged account ([email protected]) yet I wasn't able to connect
Data Source=*********.database.windows.net;Initial Catalog=*****;User [email protected];Authentication=ActiveDirectoryInteractive
[email protected]
Data Source=*********.database.windows.net;Initial Catalog=*****;User [email protected];Authentication=ActiveDirectoryInteractive
[email protected]
Further technical details
- Microsoft.Data.SqlClient version: v4.1.0 (via NuGet)
- .NET target: v5.0.14
- Microsoft Azure SQL
- Operating system: Windows 10
Expected behavior
We would expect to be able to authenticate with the user specified in the connection string, independent of other connections.
Work around (does not work, see next comment)
Yes, there is a work around. If you make both connection strings different with any other value other than User ID it works are expected.
Example, we added Connect Timeout=1001; & 1002 and now I can connect with both users.
Data Source=*********.database.windows.net;Initial Catalog=*****;User [email protected];Connect Timeout=1001;Authentication=ActiveDirectoryInteractive
[email protected]
Data Source=*********.database.windows.net;Initial Catalog=*****;User [email protected];Connect Timeout=1002;Authentication=ActiveDirectoryInteractive
[email protected]
Activity
slavergne-devolutions commentedon Mar 3, 2022
Actually after further testing the work around is wrong, it doesn't change anything. It's one of the many tests I did but not the one that changed things and got things working.
Here is what I think worked.
Step 1 connection with
*********.database.windows.netwith bothsomeuser&_someuser,_someuserwill not workStep 2 connection with
tcp:*********.database.windows.net,1433with both_someuser&someuserboth will workNote: Here we inversed the users, connect with
_someuserfirstStep 3 try step 1 again, everything will work
Once both are connected, you can change the connection string like you want, setting different connection timeout or whatever.

JRahnama commentedon Mar 4, 2022
@slavergne-devolutions we will look into that and get back to you.
slavergne-devolutions commentedon Mar 9, 2022
I think you can close this ticket, all is working normally this morning with my test code. I have not changed anything whatsoever, not a line of code or the version of the NuGet. My guess is the issue was due to some odd Azure AD issue.
I'm confirming with the client to make sure it works on their side.
JRahnama commentedon Mar 9, 2022
@slavergne-devolutions thanks for the update. Closing the issue as resolved.