From 2b022d2e484d5193461754798a3872db6073db09 Mon Sep 17 00:00:00 2001
From: Justin M <63619224+JustinMDotNet@users.noreply.github.com>
Date: Mon, 5 Oct 2020 00:56:40 -0700
Subject: [PATCH] 3326 Kusto HTTPS url fix (#1086)
* 3326 Removed sqlConnection.Open from CreateSqlConnection in ConnectionService.
* 3326 Removed unused variables and functions from ConnectedBindingContext, ConnectedBindingQueue, IBindingContext, and IConnectedBindingQueue
* 3326 Removed unused constant SqlAzureEdition and unused functions CreateSqlConnection and CreateServerConnection from ConnectionService. Removed ServerConnection, MetadataDisplayInfoProvider, Binder, and SmoMetaDataProvider from ConnectedBindingContext. Deleted SqlConnectionOpener and ISqlConnectionOpener.
---
.../Connection/ConnectionService.cs | 81 +-------
.../LanguageServices/BindingQueue.cs | 20 --
.../ConnectedBindingContext.cs | 173 +-----------------
.../LanguageServices/ConnectedBindingQueue.cs | 81 +-------
.../LanguageServices/IBindingContext.cs | 51 ------
.../IConnectedBindingQueue.cs | 4 +-
.../LanguageServices/ISqlConnectionOpener.cs | 13 --
.../LanguageServices/SqlConnectionOpener.cs | 15 --
.../ObjectExplorer/ObjectExplorerService.cs | 14 +-
.../ConnectedBindingQueueTests.cs | 24 +--
10 files changed, 15 insertions(+), 461 deletions(-)
delete mode 100644 src/Microsoft.Kusto.ServiceLayer/LanguageServices/ISqlConnectionOpener.cs
delete mode 100644 src/Microsoft.Kusto.ServiceLayer/LanguageServices/SqlConnectionOpener.cs
diff --git a/src/Microsoft.Kusto.ServiceLayer/Connection/ConnectionService.cs b/src/Microsoft.Kusto.ServiceLayer/Connection/ConnectionService.cs
index c66481bd..22877353 100644
--- a/src/Microsoft.Kusto.ServiceLayer/Connection/ConnectionService.cs
+++ b/src/Microsoft.Kusto.ServiceLayer/Connection/ConnectionService.cs
@@ -31,9 +31,8 @@ namespace Microsoft.Kusto.ServiceLayer.Connection
///
public class ConnectionService
{
- public const string AdminConnectionPrefix = "ADMIN:";
- internal const string PasswordPlaceholder = "******";
- private const string SqlAzureEdition = "SQL Azure";
+ private const string AdminConnectionPrefix = "ADMIN:";
+ private const string PasswordPlaceholder = "******";
///
/// Singleton service instance
@@ -984,7 +983,7 @@ namespace Microsoft.Kusto.ServiceLayer.Connection
/// Build a connection string builder a connection details instance
///
///
- public static SqlConnectionStringBuilder CreateConnectionStringBuilder(ConnectionDetails connectionDetails)
+ private static SqlConnectionStringBuilder CreateConnectionStringBuilder(ConnectionDetails connectionDetails)
{
SqlConnectionStringBuilder connectionBuilder;
@@ -1359,63 +1358,6 @@ namespace Microsoft.Kusto.ServiceLayer.Connection
}
}
- ///
- /// Create and open a new SqlConnection from a ConnectionInfo object
- /// Note: we need to audit all uses of this method to determine why we're
- /// bypassing normal ConnectionService connection management
- ///
- /// The connection info to connect with
- /// A plaintext string that will be included in the application name for the connection
- /// A SqlConnection created with the given connection info
- internal static SqlConnection OpenSqlConnection(ConnectionInfo connInfo, string featureName = null)
- {
- try
- {
- // capture original values
- int? originalTimeout = connInfo.ConnectionDetails.ConnectTimeout;
- bool? originalPersistSecurityInfo = connInfo.ConnectionDetails.PersistSecurityInfo;
- bool? originalPooling = connInfo.ConnectionDetails.Pooling;
-
- // increase the connection timeout to at least 30 seconds and and build connection string
- connInfo.ConnectionDetails.ConnectTimeout = Math.Max(30, originalTimeout ?? 0);
- // enable PersistSecurityInfo to handle issues in SMO where the connection context is lost in reconnections
- connInfo.ConnectionDetails.PersistSecurityInfo = true;
- // turn off connection pool to avoid hold locks on server resources after calling SqlConnection Close method
- connInfo.ConnectionDetails.Pooling = false;
- connInfo.ConnectionDetails.ApplicationName = GetApplicationNameWithFeature(connInfo.ConnectionDetails.ApplicationName, featureName);
-
- // generate connection string
- string connectionString = BuildConnectionString(connInfo.ConnectionDetails);
-
- // restore original values
- connInfo.ConnectionDetails.ConnectTimeout = originalTimeout;
- connInfo.ConnectionDetails.PersistSecurityInfo = originalPersistSecurityInfo;
- connInfo.ConnectionDetails.Pooling = originalPooling;
-
- // open a dedicated binding server connection
- using (SqlConnection sqlConn = new SqlConnection(connectionString))
- {
- // Fill in Azure authentication token if needed
- if (connInfo.ConnectionDetails.AzureAccountToken != null)
- {
- sqlConn.AccessToken = connInfo.ConnectionDetails.AzureAccountToken;
- }
-
- sqlConn.Open();
- return sqlConn;
- }
- }
- catch (Exception ex)
- {
- string error = string.Format(CultureInfo.InvariantCulture,
- "Failed opening a SqlConnection: error:{0} inner:{1} stacktrace:{2}",
- ex.Message, ex.InnerException != null ? ex.InnerException.Message : string.Empty, ex.StackTrace);
- Logger.Write(TraceEventType.Error, error);
- }
-
- return null;
- }
-
///
/// Create and open a new SqlConnection from a ConnectionInfo object
/// Note: we need to audit all uses of this method to determine why we're
@@ -1445,23 +1387,6 @@ namespace Microsoft.Kusto.ServiceLayer.Connection
return null;
}
- ///
- /// Create and open a new ServerConnection from a ConnectionInfo object.
- /// This calls ConnectionService.OpenSqlConnection and then creates a
- /// ServerConnection from it.
- ///
- /// The connection info to connect with
- /// A plaintext string that will be included in the application name for the connection
- /// A ServerConnection (wrapping a SqlConnection) created with the given connection info
- internal static ServerConnection OpenServerConnection(ConnectionInfo connInfo, string featureName = null)
- {
- SqlConnection sqlConnection = OpenSqlConnection(connInfo, featureName);
-
- return connInfo.ConnectionDetails.AzureAccountToken != null
- ? new ServerConnection(sqlConnection, new AzureAccessToken(connInfo.ConnectionDetails.AzureAccountToken))
- : new ServerConnection(sqlConnection);
- }
-
public static void EnsureConnectionIsOpen(ReliableDataSourceConnection conn, bool forceReopen = false)
{
// verify that the connection is open
diff --git a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/BindingQueue.cs b/src/Microsoft.Kusto.ServiceLayer/LanguageServices/BindingQueue.cs
index c7fbb9c5..aee96a0c 100644
--- a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/BindingQueue.cs
+++ b/src/Microsoft.Kusto.ServiceLayer/LanguageServices/BindingQueue.cs
@@ -202,15 +202,6 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
{
// disconnect existing connection
var bindingContext = this.BindingContextMap[key];
- if (bindingContext.ServerConnection != null && bindingContext.ServerConnection.IsOpen)
- {
- // Disconnecting can take some time so run it in a separate task so that it doesn't block removal
- Task.Run(() =>
- {
- bindingContext.ServerConnection.Cancel();
- bindingContext.ServerConnection.Disconnect();
- });
- }
// remove key from the map
this.BindingContextMap.Remove(key);
@@ -483,17 +474,6 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
{
_itemQueuedEvent.Dispose();
}
-
- if (this.BindingContextMap != null)
- {
- foreach (var item in this.BindingContextMap)
- {
- if (item.Value != null && item.Value.ServerConnection != null && item.Value.ServerConnection.SqlConnectionObject != null)
- {
- item.Value.ServerConnection.SqlConnectionObject.Close();
- }
- }
- }
}
private bool IsExceptionOfType(Exception ex, Type t)
diff --git a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/ConnectedBindingContext.cs b/src/Microsoft.Kusto.ServiceLayer/LanguageServices/ConnectedBindingContext.cs
index 7491a08f..e9ab30c7 100644
--- a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/ConnectedBindingContext.cs
+++ b/src/Microsoft.Kusto.ServiceLayer/LanguageServices/ConnectedBindingContext.cs
@@ -3,14 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
-using System;
using System.Threading;
-using Microsoft.SqlServer.Management.Common;
-using Microsoft.SqlServer.Management.SmoMetadataProvider;
-using Microsoft.SqlServer.Management.SqlParser.Binder;
-using Microsoft.SqlServer.Management.SqlParser.Common;
-using Microsoft.SqlServer.Management.SqlParser.MetadataProvider;
-using Microsoft.SqlServer.Management.SqlParser.Parser;
using Microsoft.Kusto.ServiceLayer.DataSource;
namespace Microsoft.Kusto.ServiceLayer.LanguageServices
@@ -20,11 +13,7 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
///
public class ConnectedBindingContext : IBindingContext
{
- private ParseOptions parseOptions;
-
- private ManualResetEvent bindingLock;
-
- private ServerConnection serverConnection;
+ private readonly ManualResetEvent bindingLock;
///
public IDataSource DataSource { get; set; }
@@ -36,7 +25,6 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
{
this.bindingLock = new ManualResetEvent(initialState: true);
this.BindingTimeout = ConnectedBindingQueue.DefaultBindingTimeout;
- this.MetadataDisplayInfoProvider = new MetadataDisplayInfoProvider();
}
///
@@ -44,39 +32,6 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
///
public bool IsConnected { get; set; }
- ///
- /// Gets or sets the binding server connection
- ///
- public ServerConnection ServerConnection
- {
- get
- {
- return this.serverConnection;
- }
- set
- {
- this.serverConnection = value;
-
- // reset the parse options so the get recreated for the current connection
- this.parseOptions = null;
- }
- }
-
- ///
- /// Gets or sets the metadata display info provider
- ///
- public MetadataDisplayInfoProvider MetadataDisplayInfoProvider { get; set; }
-
- ///
- /// Gets or sets the SMO metadata provider
- ///
- public SmoMetadataProvider SmoMetadataProvider { get; set; }
-
- ///
- /// Gets or sets the binder
- ///
- public IBinder Binder { get; set; }
-
///
/// Gets the binding lock object
///
@@ -91,130 +46,6 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
///
/// Gets or sets the binding operation timeout in milliseconds
///
- public int BindingTimeout { get; set; }
-
- ///
- /// Gets the Language Service ServerVersion
- ///
- public ServerVersion ServerVersion
- {
- get
- {
- return this.ServerConnection != null
- ? this.ServerConnection.ServerVersion
- : null;
- }
- }
-
- ///
- /// Gets the current DataEngineType
- ///
- public DatabaseEngineType DatabaseEngineType
- {
- get
- {
- return this.ServerConnection != null
- ? this.ServerConnection.DatabaseEngineType
- : DatabaseEngineType.Standalone;
- }
- }
-
- ///
- /// Gets the current connections TransactSqlVersion
- ///
- public TransactSqlVersion TransactSqlVersion
- {
- get
- {
- return this.IsConnected
- ? GetTransactSqlVersion(this.ServerVersion)
- : TransactSqlVersion.Current;
- }
- }
-
- ///
- /// Gets the current DatabaseCompatibilityLevel
- ///
- public DatabaseCompatibilityLevel DatabaseCompatibilityLevel
- {
- get
- {
- return this.IsConnected
- ? GetDatabaseCompatibilityLevel(this.ServerVersion)
- : DatabaseCompatibilityLevel.Current;
- }
- }
-
- ///
- /// Gets the current ParseOptions
- ///
- public ParseOptions ParseOptions
- {
- get
- {
- if (this.parseOptions == null)
- {
- this.parseOptions = new ParseOptions(
- batchSeparator: LanguageService.DefaultBatchSeperator,
- isQuotedIdentifierSet: true,
- compatibilityLevel: DatabaseCompatibilityLevel,
- transactSqlVersion: TransactSqlVersion);
- }
- return this.parseOptions;
- }
- }
-
-
- ///
- /// Gets the database compatibility level from a server version
- ///
- ///
- private static DatabaseCompatibilityLevel GetDatabaseCompatibilityLevel(ServerVersion serverVersion)
- {
- int versionMajor = Math.Max(serverVersion.Major, 8);
-
- switch (versionMajor)
- {
- case 8:
- return DatabaseCompatibilityLevel.Version80;
- case 9:
- return DatabaseCompatibilityLevel.Version90;
- case 10:
- return DatabaseCompatibilityLevel.Version100;
- case 11:
- return DatabaseCompatibilityLevel.Version110;
- case 12:
- return DatabaseCompatibilityLevel.Version120;
- case 13:
- return DatabaseCompatibilityLevel.Version130;
- default:
- return DatabaseCompatibilityLevel.Current;
- }
- }
-
- ///
- /// Gets the transaction sql version from a server version
- ///
- ///
- private static TransactSqlVersion GetTransactSqlVersion(ServerVersion serverVersion)
- {
- int versionMajor = Math.Max(serverVersion.Major, 9);
-
- switch (versionMajor)
- {
- case 9:
- case 10:
- // In case of 10.0 we still use Version 10.5 as it is the closest available.
- return TransactSqlVersion.Version105;
- case 11:
- return TransactSqlVersion.Version110;
- case 12:
- return TransactSqlVersion.Version120;
- case 13:
- return TransactSqlVersion.Version130;
- default:
- return TransactSqlVersion.Current;
- }
- }
+ public int BindingTimeout { get; set; }
}
}
diff --git a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/ConnectedBindingQueue.cs b/src/Microsoft.Kusto.ServiceLayer/LanguageServices/ConnectedBindingQueue.cs
index ee947257..b0d0cfbc 100644
--- a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/ConnectedBindingQueue.cs
+++ b/src/Microsoft.Kusto.ServiceLayer/LanguageServices/ConnectedBindingQueue.cs
@@ -5,13 +5,8 @@
using System;
using System.Composition;
-using Microsoft.SqlServer.Management.SmoMetadataProvider;
-using Microsoft.SqlServer.Management.SqlParser.Binder;
-using Microsoft.SqlServer.Management.SqlParser.MetadataProvider;
using Microsoft.Kusto.ServiceLayer.Connection;
using Microsoft.Kusto.ServiceLayer.Connection.Contracts;
-using Microsoft.Kusto.ServiceLayer.SqlContext;
-using Microsoft.Kusto.ServiceLayer.Workspace;
using Microsoft.Kusto.ServiceLayer.DataSource;
namespace Microsoft.Kusto.ServiceLayer.LanguageServices
@@ -23,21 +18,11 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
public class ConnectedBindingQueue : BindingQueue, IConnectedBindingQueue
{
internal const int DefaultBindingTimeout = 500;
- private readonly ISqlConnectionOpener _connectionOpener;
private readonly IDataSourceFactory _dataSourceFactory;
- ///
- /// Gets the current settings
- ///
- private SqlToolsSettings CurrentSettings
- {
- get { return WorkspaceService.Instance.CurrentSettings; }
- }
-
[ImportingConstructor]
- public ConnectedBindingQueue(ISqlConnectionOpener sqlConnectionOpener, IDataSourceFactory dataSourceFactory)
+ public ConnectedBindingQueue(IDataSourceFactory dataSourceFactory)
{
- _connectionOpener = sqlConnectionOpener;
_dataSourceFactory = dataSourceFactory;
}
@@ -67,52 +52,6 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
return Uri.EscapeUriString(key);
}
- ///
- /// Generate a unique key based on the ConnectionInfo object
- ///
- ///
- ///
- private string GetConnectionContextKey(string serverName, string databaseName)
- {
- return string.Format("{0}_{1}",
- serverName ?? "NULL",
- databaseName ?? "NULL");
-
- }
-
- public void CloseConnections(string serverName, string databaseName, int millisecondsTimeout)
- {
- string connectionKey = GetConnectionContextKey(serverName, databaseName);
- var contexts = GetBindingContexts(connectionKey);
- foreach (var bindingContext in contexts)
- {
- if (bindingContext.BindingLock.WaitOne(millisecondsTimeout))
- {
- bindingContext.ServerConnection.Disconnect();
- }
- }
- }
-
- public void OpenConnections(string serverName, string databaseName, int millisecondsTimeout)
- {
- string connectionKey = GetConnectionContextKey(serverName, databaseName);
- var contexts = GetBindingContexts(connectionKey);
- foreach (var bindingContext in contexts)
- {
- if (bindingContext.BindingLock.WaitOne(millisecondsTimeout))
- {
- try
- {
- bindingContext.ServerConnection.Connect();
- }
- catch
- {
- //TODO: remove the binding context?
- }
- }
- }
- }
-
public void RemoveBindingContext(ConnectionInfo connInfo)
{
string connectionKey = GetConnectionContextKey(connInfo.ConnectionDetails);
@@ -157,24 +96,10 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
try
{
bindingContext.BindingLock.Reset();
-
- // populate the binding context to work with the SMO metadata provider
- bindingContext.ServerConnection = _connectionOpener.OpenServerConnection(connInfo, featureName);
-
+
string connectionString = ConnectionService.BuildConnectionString(connInfo.ConnectionDetails);
bindingContext.DataSource = _dataSourceFactory.Create(DataSourceType.Kusto, connectionString, connInfo.ConnectionDetails.AzureAccountToken);
-
- if (needMetadata)
- {
- bindingContext.SmoMetadataProvider = SmoMetadataProvider.CreateConnectedProvider(bindingContext.ServerConnection);
- bindingContext.MetadataDisplayInfoProvider = new MetadataDisplayInfoProvider();
- bindingContext.MetadataDisplayInfoProvider.BuiltInCasing =
- this.CurrentSettings.SqlTools.IntelliSense.LowerCaseSuggestions.Value
- ? CasingStyle.Lowercase : CasingStyle.Uppercase;
- bindingContext.Binder = BinderProvider.CreateBinder(bindingContext.SmoMetadataProvider);
- }
-
- bindingContext.BindingTimeout = ConnectedBindingQueue.DefaultBindingTimeout;
+ bindingContext.BindingTimeout = DefaultBindingTimeout;
bindingContext.IsConnected = true;
}
catch (Exception)
diff --git a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/IBindingContext.cs b/src/Microsoft.Kusto.ServiceLayer/LanguageServices/IBindingContext.cs
index 2163f816..536e5676 100644
--- a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/IBindingContext.cs
+++ b/src/Microsoft.Kusto.ServiceLayer/LanguageServices/IBindingContext.cs
@@ -4,12 +4,6 @@
//
using System.Threading;
-using Microsoft.SqlServer.Management.Common;
-using Microsoft.SqlServer.Management.SmoMetadataProvider;
-using Microsoft.SqlServer.Management.SqlParser.Binder;
-using Microsoft.SqlServer.Management.SqlParser.Common;
-using Microsoft.SqlServer.Management.SqlParser.MetadataProvider;
-using Microsoft.SqlServer.Management.SqlParser.Parser;
using Microsoft.Kusto.ServiceLayer.DataSource;
@@ -25,31 +19,11 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
///
bool IsConnected { get; set; }
- ///
- /// Gets or sets the binding server connection
- ///
- ServerConnection ServerConnection { get; set; }
-
///
/// Gets or sets data source interface
///
IDataSource DataSource { get; set; }
- ///
- /// Gets or sets the metadata display info provider
- ///
- MetadataDisplayInfoProvider MetadataDisplayInfoProvider { get; set; }
-
- ///
- /// Gets or sets the SMO metadata provider
- ///
- SmoMetadataProvider SmoMetadataProvider { get; set; }
-
- ///
- /// Gets or sets the binder
- ///
- IBinder Binder { get; set; }
-
///
/// Gets the binding lock object
///
@@ -59,30 +33,5 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
/// Gets or sets the binding operation timeout in milliseconds
///
int BindingTimeout { get; set; }
-
- ///
- /// Gets or sets the current connection parse options
- ///
- ParseOptions ParseOptions { get; }
-
- ///
- /// Gets or sets the current connection server version
- ///
- ServerVersion ServerVersion { get; }
-
- ///
- /// Gets or sets the database engine type
- ///
- DatabaseEngineType DatabaseEngineType { get; }
-
- ///
- /// Gets or sets the T-SQL version
- ///
- TransactSqlVersion TransactSqlVersion { get; }
-
- ///
- /// Gets or sets the database compatibility level
- ///
- DatabaseCompatibilityLevel DatabaseCompatibilityLevel { get; }
}
}
diff --git a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/IConnectedBindingQueue.cs b/src/Microsoft.Kusto.ServiceLayer/LanguageServices/IConnectedBindingQueue.cs
index f777fdb3..99b18950 100644
--- a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/IConnectedBindingQueue.cs
+++ b/src/Microsoft.Kusto.ServiceLayer/LanguageServices/IConnectedBindingQueue.cs
@@ -7,9 +7,7 @@ namespace Microsoft.Kusto.ServiceLayer.LanguageServices
public interface IConnectedBindingQueue
{
event BindingQueue.UnhandledExceptionDelegate OnUnhandledException;
-
- void CloseConnections(string serverName, string databaseName, int millisecondsTimeout);
- void OpenConnections(string serverName, string databaseName, int millisecondsTimeout);
+
string AddConnectionContext(ConnectionInfo connInfo, bool needMetadata, string featureName = null, bool overwrite = false);
void Dispose();
bool IsBindingContextConnected(string key);
diff --git a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/ISqlConnectionOpener.cs b/src/Microsoft.Kusto.ServiceLayer/LanguageServices/ISqlConnectionOpener.cs
deleted file mode 100644
index a2eba050..00000000
--- a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/ISqlConnectionOpener.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using Microsoft.Kusto.ServiceLayer.Connection;
-using Microsoft.SqlServer.Management.Common;
-
-namespace Microsoft.Kusto.ServiceLayer.LanguageServices
-{
- public interface ISqlConnectionOpener
- {
- ///
- /// Virtual method used to support mocking and testing
- ///
- ServerConnection OpenServerConnection(ConnectionInfo connInfo, string featureName);
- }
-}
\ No newline at end of file
diff --git a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/SqlConnectionOpener.cs b/src/Microsoft.Kusto.ServiceLayer/LanguageServices/SqlConnectionOpener.cs
deleted file mode 100644
index eb010220..00000000
--- a/src/Microsoft.Kusto.ServiceLayer/LanguageServices/SqlConnectionOpener.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System.Composition;
-using Microsoft.Kusto.ServiceLayer.Connection;
-using Microsoft.SqlServer.Management.Common;
-
-namespace Microsoft.Kusto.ServiceLayer.LanguageServices
-{
- [Export(typeof(ISqlConnectionOpener))]
- public class SqlConnectionOpener : ISqlConnectionOpener
- {
- public ServerConnection OpenServerConnection(ConnectionInfo connInfo, string featureName)
- {
- return ConnectionService.OpenServerConnection(connInfo, featureName);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Microsoft.Kusto.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs b/src/Microsoft.Kusto.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs
index 68096e78..a1073fc1 100644
--- a/src/Microsoft.Kusto.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs
+++ b/src/Microsoft.Kusto.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs
@@ -412,19 +412,7 @@ namespace Microsoft.Kusto.ServiceLayer.ObjectExplorer
}
response.Nodes = nodes;
response.ErrorMessage = node.ErrorMessage;
- try
- {
- // SMO changes the database when getting sql objects. Make sure the database is changed back to the original one
- if (bindingContext.ServerConnection.CurrentDatabase != bindingContext.ServerConnection.DatabaseName)
- {
- bindingContext.ServerConnection.SqlConnectionObject.ChangeDatabase(bindingContext.ServerConnection.DatabaseName);
- }
- }
- catch(Exception ex)
- {
- Logger.Write(TraceEventType.Warning, $"Failed to change the database in OE connection. error: {ex.Message}");
- // We should just try to change the connection. If it fails, there's not much we can do
- }
+
return response;
});
diff --git a/test/Microsoft.Kusto.ServiceLayer.UnitTests/LanguageServices/ConnectedBindingQueueTests.cs b/test/Microsoft.Kusto.ServiceLayer.UnitTests/LanguageServices/ConnectedBindingQueueTests.cs
index 581e1feb..c484699e 100644
--- a/test/Microsoft.Kusto.ServiceLayer.UnitTests/LanguageServices/ConnectedBindingQueueTests.cs
+++ b/test/Microsoft.Kusto.ServiceLayer.UnitTests/LanguageServices/ConnectedBindingQueueTests.cs
@@ -66,9 +66,8 @@ namespace Microsoft.Kusto.ServiceLayer.UnitTests.LanguageServices
[Test]
public void AddConnectionContext_Returns_EmptyString_For_NullConnectionInfo()
{
- var connectionOpenerMock = new Mock();
var dataSourceFactory = new Mock();
- var connectedBindingQueue = new ConnectedBindingQueue(connectionOpenerMock.Object, dataSourceFactory.Object);
+ var connectedBindingQueue = new ConnectedBindingQueue(dataSourceFactory.Object);
var connectionKey = connectedBindingQueue.AddConnectionContext(null, false);
Assert.AreEqual(string.Empty, connectionKey);
@@ -81,9 +80,8 @@ namespace Microsoft.Kusto.ServiceLayer.UnitTests.LanguageServices
var connectionFactory = new Mock();
var connectionInfo = new ConnectionInfo(connectionFactory.Object, "ownerUri", connectionDetails);
- var connectionOpenerMock = new Mock();
var dataSourceFactory = new Mock();
- var connectedBindingQueue = new ConnectedBindingQueue(connectionOpenerMock.Object, dataSourceFactory.Object);
+ var connectedBindingQueue = new ConnectedBindingQueue(dataSourceFactory.Object);
var connectionKey = connectedBindingQueue.AddConnectionContext(connectionInfo, false, "featureName");
Assert.AreEqual("NULL_NULL_NULL_NULL", connectionKey);
@@ -96,12 +94,6 @@ namespace Microsoft.Kusto.ServiceLayer.UnitTests.LanguageServices
var connectionFactory = new Mock();
var connectionInfo = new ConnectionInfo(connectionFactory.Object, "ownerUri", connectionDetails);
- var connectionOpenerMock = new Mock();
- var fakeServerConnection = new ServerConnection();
- connectionOpenerMock
- .Setup(x => x.OpenServerConnection(It.IsAny(), It.IsAny()))
- .Returns(fakeServerConnection);
-
var dataSourceFactory = new Mock();
var dataSourceMock = new Mock();
dataSourceFactory
@@ -109,18 +101,14 @@ namespace Microsoft.Kusto.ServiceLayer.UnitTests.LanguageServices
.Returns(dataSourceMock.Object);
var connectedBindingQueue =
- new ConnectedBindingQueue(connectionOpenerMock.Object, dataSourceFactory.Object);
+ new ConnectedBindingQueue(dataSourceFactory.Object);
var connectionKey =
connectedBindingQueue.AddConnectionContext(connectionInfo, needsMetadata, "featureName");
var bindingContext = connectedBindingQueue.GetOrCreateBindingContext(connectionKey);
-
- Assert.AreEqual(fakeServerConnection, bindingContext.ServerConnection);
+
Assert.AreEqual(dataSourceMock.Object, bindingContext.DataSource);
Assert.AreEqual(500, bindingContext.BindingTimeout);
Assert.AreEqual(true, bindingContext.IsConnected);
- Assert.AreEqual(CasingStyle.Uppercase, bindingContext.MetadataDisplayInfoProvider.BuiltInCasing);
- Assert.IsNull(bindingContext.SmoMetadataProvider);
- Assert.IsNull(bindingContext.Binder);
}
[Test]
@@ -130,12 +118,10 @@ namespace Microsoft.Kusto.ServiceLayer.UnitTests.LanguageServices
var connectionFactory = new Mock();
var connectionInfo = new ConnectionInfo(connectionFactory.Object, "ownerUri", connectionDetails);
- var connectionOpenerMock = new Mock();
var dataSourceFactory = new Mock();
- var connectedBindingQueue = new ConnectedBindingQueue(connectionOpenerMock.Object, dataSourceFactory.Object);
+ var connectedBindingQueue = new ConnectedBindingQueue(dataSourceFactory.Object);
var connectionKey = connectedBindingQueue.AddConnectionContext(connectionInfo, false, "featureName");
-
connectedBindingQueue.RemoveBindingContext(connectionInfo);
Assert.IsFalse(connectedBindingQueue.BindingContextMap.ContainsKey(connectionKey));