mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
fix delay in query execution (#2109)
* fix delay in query execution * fix test case
This commit is contained in:
@@ -491,14 +491,19 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
{
|
{
|
||||||
if (connectionParams != null && connectionParams.Type == ConnectionType.Default && !string.IsNullOrWhiteSpace(connectionParams.OwnerUri))
|
if (connectionParams != null && connectionParams.Type == ConnectionType.Default && !string.IsNullOrWhiteSpace(connectionParams.OwnerUri))
|
||||||
{
|
{
|
||||||
if (connectionParams.OwnerUri.ToLowerInvariant().StartsWith("dashboard://"))
|
var uri = connectionParams.OwnerUri.ToLowerInvariant();
|
||||||
|
if (uri.StartsWith("dashboard://"))
|
||||||
{
|
{
|
||||||
connectionParams.Purpose = ConnectionType.Dashboard;
|
connectionParams.Purpose = ConnectionType.Dashboard;
|
||||||
}
|
}
|
||||||
else if (connectionParams.OwnerUri.ToLowerInvariant().StartsWith("connection://"))
|
else if (uri.StartsWith("connection://"))
|
||||||
{
|
{
|
||||||
connectionParams.Purpose = ConnectionType.GeneralConnection;
|
connectionParams.Purpose = ConnectionType.GeneralConnection;
|
||||||
}
|
}
|
||||||
|
else if (uri.StartsWith("untitled:sqlquery") || (uri.StartsWith("file://") && uri.EndsWith(".sql")))
|
||||||
|
{
|
||||||
|
connectionParams.Purpose = ConnectionType.Query;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (connectionParams != null)
|
else if (connectionParams != null)
|
||||||
{
|
{
|
||||||
@@ -1045,26 +1050,32 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
bool disconnect = false;
|
bool disconnect = false;
|
||||||
if (connection.ConnectionString != null){
|
if (connection.ConnectionString != null)
|
||||||
|
{
|
||||||
int totalCount = 0;
|
int totalCount = 0;
|
||||||
foreach (KeyValuePair<string, ConnectionInfo> entry in OwnerToConnectionMap)
|
foreach (KeyValuePair<string, ConnectionInfo> entry in OwnerToConnectionMap)
|
||||||
{
|
{
|
||||||
foreach (DbConnection value in entry.Value.AllConnections) {
|
foreach (DbConnection value in entry.Value.AllConnections)
|
||||||
if(value.ConnectionString == connection.ConnectionString) {
|
{
|
||||||
|
if (value.ConnectionString == connection.ConnectionString)
|
||||||
|
{
|
||||||
totalCount++;
|
totalCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(totalCount == 1) {
|
if (totalCount == 1)
|
||||||
|
{
|
||||||
disconnect = true;
|
disconnect = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
disconnect = true;
|
disconnect = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(disconnect) {
|
if (disconnect)
|
||||||
|
{
|
||||||
connection.Close();
|
connection.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1870,7 +1881,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
connInfo.ConnectionDetails.PersistSecurityInfo = true;
|
connInfo.ConnectionDetails.PersistSecurityInfo = true;
|
||||||
|
|
||||||
// turn off connection pool to avoid hold locks on server resources after calling SqlConnection Close method
|
// turn off connection pool to avoid hold locks on server resources after calling SqlConnection Close method
|
||||||
if (shouldForceDisablePooling) {
|
if (shouldForceDisablePooling)
|
||||||
|
{
|
||||||
connInfo.ConnectionDetails.Pooling = false;
|
connInfo.ConnectionDetails.Pooling = false;
|
||||||
}
|
}
|
||||||
connInfo.ConnectionDetails.ApplicationName = GetApplicationNameWithFeature(connInfo.ConnectionDetails.ApplicationName, featureName);
|
connInfo.ConnectionDetails.ApplicationName = GetApplicationNameWithFeature(connInfo.ConnectionDetails.ApplicationName, featureName);
|
||||||
|
|||||||
@@ -448,7 +448,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Locate and setup the connection
|
// Locate and setup the connection
|
||||||
queryConnection = await ConnectionService.Instance.GetOrOpenConnection(editorConnection.OwnerUri, ConnectionType.Query);
|
queryConnection = await ConnectionService.Instance.GetOrOpenConnection(editorConnection.OwnerUri, ConnectionType.Default);
|
||||||
onErrorAction = OnErrorAction.Ignore;
|
onErrorAction = OnErrorAction.Ignore;
|
||||||
sqlConn = queryConnection as ReliableSqlConnection;
|
sqlConn = queryConnection as ReliableSqlConnection;
|
||||||
if (sqlConn != null)
|
if (sqlConn != null)
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
|||||||
query.Execute();
|
query.Execute();
|
||||||
query.ExecutionTask.Wait();
|
query.ExecutionTask.Wait();
|
||||||
|
|
||||||
// We should see two DbConnections
|
// We should see 1 DbConnections
|
||||||
Assert.AreEqual(2, connectionInfo.CountConnections);
|
Assert.AreEqual(1, connectionInfo.CountConnections);
|
||||||
|
|
||||||
// If we run another query
|
// If we run another query
|
||||||
query = new Query(Constants.StandardQuery, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
query = new Query(Constants.StandardQuery, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
||||||
@@ -54,7 +54,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
|||||||
query.ExecutionTask.Wait();
|
query.ExecutionTask.Wait();
|
||||||
|
|
||||||
// We should still have 2 DbConnections
|
// We should still have 2 DbConnections
|
||||||
Assert.AreEqual(2, connectionInfo.CountConnections);
|
Assert.AreEqual(1, connectionInfo.CountConnections);
|
||||||
|
|
||||||
// If we disconnect, we should remain in a consistent state to do it over again
|
// If we disconnect, we should remain in a consistent state to do it over again
|
||||||
// e.g. loop and do it over again
|
// e.g. loop and do it over again
|
||||||
|
|||||||
Reference in New Issue
Block a user