microsoft / vscode-mssql

Visual Studio Code SQL Server extension.
Other
1.55k stars 458 forks source link

Connection dialog doesn't work with ADO.NET Microsoft Entra passwordless authentication #18330

Closed croblesm closed 3 weeks ago

croblesm commented 1 month ago

I'm trying to connect an existing Azure SQL Database by using copying the ADO.NET (Microsoft Entra passwordless authentication) connection string, but it fails with the Value cannot be null. (Parameter 'User ID') error.

This is the connection string I'm copying/pasting:

Server=tcp:<MyServer>.database.windows.net,1433;Initial Catalog=<MyDatabase>;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication="Active Directory Default";

Error from Connection Dialog: Image

croblesm commented 1 month ago

mssql: Failed to connect: System.ArgumentNullException: Value cannot be null. (Parameter 'User ID') at Microsoft.Data.SqlClient.SqlConnectionStringBuilder.SetValue(String keyword, String value) at Microsoft.Data.SqlClient.SqlConnectionStringBuilder.set_UserID(String value) at Microsoft.SqlTools.ServiceLayer.Connection.ConnectionService.CreateConnectionStringBuilder(ConnectionDetails connectionDetails, Boolean forceDisablePooling) in /_/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs:line 1419 at Microsoft.SqlTools.ServiceLayer.Connection.ConnectionService.BuildConnectionString(ConnectionDetails connectionDetails, Boolean forceDisablePooling) in /_/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs:line 1372 at Microsoft.SqlTools.ServiceLayer.Connection.ConnectionService.TryOpenConnection(ConnectionInfo connectionInfo, ConnectParams connectionParams) in /_/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs:line 691

Benjin commented 3 weeks ago

This issue actually ended up having nothing to do with Entra passwordless auth. The bug was that the authentication type from the Parameters input was still being set even though the user had entered a connection string. SqlToolsService saw "SqlAuth" set and proceeded to do a bunch of extra validation, and failed because User ID - which is necessary for SqlAuth - wasn't set.

If anyone finds that Entra passwordless auth is not working, please open a new bug.