fix delay in query execution (#2109)

* fix delay in query execution

* fix test case
This commit is contained in:
Alan Ren
2023-06-19 16:31:47 -07:00
committed by GitHub
parent 6fe0b300e5
commit 7f6b357eb0
3 changed files with 28 additions and 16 deletions

View File

@@ -491,14 +491,19 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
{
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;
}
else if (connectionParams.OwnerUri.ToLowerInvariant().StartsWith("connection://"))
else if (uri.StartsWith("connection://"))
{
connectionParams.Purpose = ConnectionType.GeneralConnection;
}
else if (uri.StartsWith("untitled:sqlquery") || (uri.StartsWith("file://") && uri.EndsWith(".sql")))
{
connectionParams.Purpose = ConnectionType.Query;
}
}
else if (connectionParams != null)
{
@@ -1044,27 +1049,33 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
{
try
{
bool disconnect = false;
if (connection.ConnectionString != null){
bool disconnect = false;
if (connection.ConnectionString != null)
{
int totalCount = 0;
foreach (KeyValuePair<string, ConnectionInfo> entry in OwnerToConnectionMap)
{
foreach (DbConnection value in entry.Value.AllConnections) {
if(value.ConnectionString == connection.ConnectionString) {
foreach (DbConnection value in entry.Value.AllConnections)
{
if (value.ConnectionString == connection.ConnectionString)
{
totalCount++;
}
}
}
if(totalCount == 1) {
disconnect = true;
if (totalCount == 1)
{
disconnect = true;
}
}
else {
else
{
disconnect = true;
}
if(disconnect) {
if (disconnect)
{
connection.Close();
}
}
@@ -1870,7 +1881,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
connInfo.ConnectionDetails.PersistSecurityInfo = true;
// 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.ApplicationName = GetApplicationNameWithFeature(connInfo.ConnectionDetails.ApplicationName, featureName);

View File

@@ -448,7 +448,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
}
// 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;
sqlConn = queryConnection as ReliableSqlConnection;
if (sqlConn != null)