mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Detect system connection for OE if database display name is blank (#583)
This commit is contained in:
@@ -458,7 +458,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
||||
ObjectExplorerSession session = null;
|
||||
connectionDetails.PersistSecurityInfo = true;
|
||||
ConnectParams connectParams = new ConnectParams() { OwnerUri = uri, Connection = connectionDetails, Type = Connection.ConnectionType.ObjectExplorer };
|
||||
string connectionDatabase = connectionDetails.DatabaseName;
|
||||
bool isDefaultOrSystemDatabase = DatabaseUtils.IsSystemDatabaseConnection(connectionDetails.DatabaseName) || string.IsNullOrWhiteSpace(connectionDetails.DatabaseDisplayName);
|
||||
|
||||
ConnectionInfo connectionInfo;
|
||||
ConnectionCompleteParams connectionResult = await Connect(connectParams, uri);
|
||||
@@ -480,7 +480,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
||||
waitForLockTimeout: timeout,
|
||||
bindOperation: (bindingContext, cancelToken) =>
|
||||
{
|
||||
session = ObjectExplorerSession.CreateSession(connectionResult, serviceProvider, bindingContext.ServerConnection, connectionDatabase);
|
||||
session = ObjectExplorerSession.CreateSession(connectionResult, serviceProvider, bindingContext.ServerConnection, isDefaultOrSystemDatabase);
|
||||
session.ConnectionInfo = connectionInfo;
|
||||
|
||||
sessionMap.AddOrUpdate(uri, session, (key, oldSession) => session);
|
||||
@@ -729,11 +729,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
public static ObjectExplorerSession CreateSession(ConnectionCompleteParams response, IMultiServiceProvider serviceProvider, ServerConnection serverConnection, string connectionDatabase)
|
||||
public static ObjectExplorerSession CreateSession(ConnectionCompleteParams response, IMultiServiceProvider serviceProvider, ServerConnection serverConnection, bool isDefaultOrSystemDatabase)
|
||||
{
|
||||
ServerNode rootNode = new ServerNode(response, serviceProvider, serverConnection);
|
||||
var session = new ObjectExplorerSession(response.OwnerUri, rootNode, serviceProvider, serviceProvider.GetService<ConnectionService>());
|
||||
if (!DatabaseUtils.IsSystemDatabaseConnection(connectionDatabase))
|
||||
if (!isDefaultOrSystemDatabase)
|
||||
{
|
||||
// Assuming the databases are in a folder under server node
|
||||
DatabaseTreeNode databaseNode = new DatabaseTreeNode(rootNode, response.ConnectionSummary.DatabaseName);
|
||||
|
||||
@@ -182,6 +182,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
||||
connectParams.Connection = new ConnectionDetails();
|
||||
connectParams.Connection.ServerName = connectionProfile.ServerName;
|
||||
connectParams.Connection.DatabaseName = connectionProfile.Database;
|
||||
connectParams.Connection.DatabaseDisplayName = connectionProfile.Database;
|
||||
connectParams.Connection.UserName = connectionProfile.User;
|
||||
connectParams.Connection.Password = connectionProfile.Password;
|
||||
connectParams.Connection.MaxPoolSize = 200;
|
||||
@@ -189,6 +190,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
||||
if (!string.IsNullOrEmpty(databaseName))
|
||||
{
|
||||
connectParams.Connection.DatabaseName = databaseName;
|
||||
connectParams.Connection.DatabaseDisplayName = databaseName;
|
||||
}
|
||||
if (key == DefaultSqlAzureInstanceKey || key == DefaultSqlAzureV12InstanceKey)
|
||||
{
|
||||
|
||||
@@ -133,6 +133,21 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
|
||||
await CreateSessionRequestAndVerifyServerNodeHelper(details);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateSessionRequestWithDefaultConnectionReturnsServerSuccessAndNodeInfo()
|
||||
{
|
||||
// Given the connection service fails to connect
|
||||
ConnectionDetails details = new ConnectionDetails()
|
||||
{
|
||||
UserName = "user",
|
||||
Password = "password",
|
||||
DatabaseName = "testdb",
|
||||
ServerName = "serverName",
|
||||
DatabaseDisplayName = ""
|
||||
};
|
||||
await CreateSessionRequestAndVerifyServerNodeHelper(details);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExpandNodeGivenValidSessionShouldReturnTheNodeChildren()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user