mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-22 09:35:38 -05:00
Update connection logic to handle multiple connections per URI (#176)
* Add CancelTokenKey for uniquely identifying cancelations of Connections associated with an OwnerUri and ConnectionType string. * Update ConnectionInfo to use ConcurrentDictionary of DbConnection instances. Add wrapper functions for the ConcurrentDictionary. * Refactor Connect and Disconnect in ConnectionService. * Update ConnectionService: Handle multiple connections per ConnectionInfo. Handle cancelation tokens uniquely identified with CancelTokenKey. Add GetOrOpenConnection() for other services to request an existing or create a new DbConnection. * Add ConnectionType.cs for ConnectionType strings. * Add ConnectionType string to ConnectParams, ConnectionCompleteNotification, DisconnectParams. * Update Query ExecuteInternal to use the dedicated query connection and GetOrOpenConnection(). * Update test library to account for multiple connections in ConnectionInfo. * Write tests ensuring multiple connections don’t create redundant data. * Write tests ensuring database changes affect all connections of a given ConnectionInfo. * Write tests for TRANSACTION statements and temp tables.
This commit is contained in:
@@ -685,19 +685,21 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
{
|
||||
var result = await TestObjects.InitLiveConnectionInfo();
|
||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||
DbConnection connection = connInfo.ConnectionTypeToConnectionMap[ConnectionType.Default];
|
||||
|
||||
Assert.True(ReliableConnectionHelper.IsAuthenticatingDatabaseMaster(connInfo.SqlConnection));
|
||||
|
||||
Assert.True(ReliableConnectionHelper.IsAuthenticatingDatabaseMaster(connection));
|
||||
|
||||
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
|
||||
Assert.True(ReliableConnectionHelper.IsAuthenticatingDatabaseMaster(builder));
|
||||
ReliableConnectionHelper.TryAddAlwaysOnConnectionProperties(builder, new SqlConnectionStringBuilder());
|
||||
|
||||
Assert.NotNull(ReliableConnectionHelper.GetServerName(connInfo.SqlConnection));
|
||||
Assert.NotNull(ReliableConnectionHelper.ReadServerVersion(connInfo.SqlConnection));
|
||||
Assert.NotNull(ReliableConnectionHelper.GetServerName(connection));
|
||||
Assert.NotNull(ReliableConnectionHelper.ReadServerVersion(connection));
|
||||
|
||||
Assert.NotNull(ReliableConnectionHelper.GetAsSqlConnection(connInfo.SqlConnection));
|
||||
Assert.NotNull(ReliableConnectionHelper.GetAsSqlConnection(connection));
|
||||
|
||||
ReliableConnectionHelper.ServerInfo info = ReliableConnectionHelper.GetServerVersion(connInfo.SqlConnection);
|
||||
ReliableConnectionHelper.ServerInfo info = ReliableConnectionHelper.GetServerVersion(connection);
|
||||
Assert.NotNull(ReliableConnectionHelper.IsVersionGreaterThan2012RTM(info));
|
||||
}
|
||||
|
||||
@@ -728,8 +730,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
{
|
||||
var result = await TestObjects.InitLiveConnectionInfo();
|
||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||
DbConnection dbConnection;
|
||||
connInfo.TryGetConnection(ConnectionType.Default, out dbConnection);
|
||||
|
||||
var connection = connInfo.SqlConnection as ReliableSqlConnection;
|
||||
var connection = dbConnection as ReliableSqlConnection;
|
||||
var command = new ReliableSqlConnection.ReliableSqlCommand(connection);
|
||||
Assert.NotNull(command.Connection);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user