Only opening connections when access token is provided (#2262)

* Only opening connections when connection string is provided

* undoing change

* Adding comment for context

* Adding comment for context

* Formatting file

* Fixing comment
This commit is contained in:
Aasim Khan
2023-10-03 20:25:22 -07:00
committed by GitHub
parent a244c86477
commit 5a8687219d

View File

@@ -38,10 +38,18 @@ namespace Microsoft.SqlTools.SqlCore.ObjectExplorer
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.AccessToken = accessToken?.Token;
conn.Open();
// In case of access token based connections, we need to open the sql connection first before creating the server connection
// Not doing so will result in an exception when trying to call 'Connect' on the server connection
if (accessToken != null)
{
conn.AccessToken = accessToken.Token;
await conn.OpenAsync();
}
ServerConnection connection = new ServerConnection(conn);
connection.AccessToken = accessToken as IRenewableToken;
if (accessToken != null)
{
connection.AccessToken = accessToken as IRenewableToken;
}
return await Expand(connection, accessToken, nodePath, serverInfo, options, filters);
}
}
@@ -120,10 +128,11 @@ namespace Microsoft.SqlTools.SqlCore.ObjectExplorer
{
SmoQueryContext nodeContext = node.GetContextAs<SmoQueryContext>() ?? throw new ArgumentException("Node does not have a valid context");
if(options.GroupBySchemaFlagGetter != null)
if (options.GroupBySchemaFlagGetter != null)
{
nodeContext.GroupBySchemaFlag = options.GroupBySchemaFlagGetter;
}
if (!nodeContext.Server.ConnectionContext.IsOpen && securityToken != null)
{
var underlyingSqlConnection = nodeContext.Server.ConnectionContext.SqlConnectionObject;