Skip to content

Commit 0ccc01e

Browse files
authored
fixed a bug with OE connection changed the db name and blocked restore (#570)
1 parent 1c2b44f commit 0ccc01e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,19 @@ internal ExpandResponse QueueExpandNodeRequest(ObjectExplorerSession session, st
414414
}
415415
response.Nodes = nodes;
416416
response.ErrorMessage = node.ErrorMessage;
417+
try
418+
{
419+
// SMO changes the database when getting sql objects. Make sure the database is changed back to the original one
420+
if (bindingContext.ServerConnection.CurrentDatabase != bindingContext.ServerConnection.DatabaseName)
421+
{
422+
bindingContext.ServerConnection.SqlConnectionObject.ChangeDatabase(bindingContext.ServerConnection.DatabaseName);
423+
}
424+
}
425+
catch(Exception ex)
426+
{
427+
Logger.Write(LogLevel.Warning, $"Failed to change the database in OE connection. error: {ex.Message}");
428+
// We should just try to change the connection. If it fails, there's not much we can do
429+
}
417430
return response;
418431
});
419432

0 commit comments

Comments
 (0)