mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Do not update the DB name when connecting to DB pool (#1186)
* Do not update the DB name when connecting to DB pool * Fix typo in the connection service
This commit is contained in:
@@ -423,7 +423,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
|
||||
// Update with the actual database name in connectionInfo and result
|
||||
// Doing this here as we know the connection is open - expect to do this only on connecting
|
||||
connectionInfo.ConnectionDetails.DatabaseName = connection.Database;
|
||||
// Do not update the DB name if it is a DB Pool database name (e.g. "db@pool")
|
||||
if (!ConnectionService.IsDbPool(connectionInfo.ConnectionDetails.DatabaseName))
|
||||
{
|
||||
connectionInfo.ConnectionDetails.DatabaseName = connection.Database;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(connectionInfo.ConnectionDetails.ConnectionString))
|
||||
{
|
||||
// If the connection was set up with a connection string, use the connection string to get the details
|
||||
@@ -1612,6 +1617,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsDbPool(string databaseName)
|
||||
{
|
||||
return databaseName != null ? databaseName.IndexOf('@') != -1 : false;
|
||||
}
|
||||
}
|
||||
|
||||
public class AzureAccessToken : IRenewableToken
|
||||
|
||||
@@ -1663,5 +1663,16 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
// Then the connection factory got called with details including an account token
|
||||
mockFactory.Verify(factory => factory.CreateSqlConnection(It.IsAny<string>(), It.Is<string>(accountToken => accountToken == azureAccountToken)), Times.Once());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test is IsDbPool method correctly works for various database names
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void CheckIsDbPool()
|
||||
{
|
||||
Assert.IsTrue(ConnectionService.IsDbPool("db@pool"));
|
||||
Assert.IsFalse(ConnectionService.IsDbPool("db"));
|
||||
Assert.IsFalse(ConnectionService.IsDbPool(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user