mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-28 17:24:27 -05:00
Modify Get Connection String Request to use connection details (#1394)
* connection string accepts connectionInfo * get connection string from disconnected scenarios
This commit is contained in:
@@ -1317,27 +1317,34 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
{
|
||||
string connectionString = string.Empty;
|
||||
ConnectionInfo info;
|
||||
if (TryFindConnection(connStringParams.OwnerUri, out info))
|
||||
SqlConnectionStringBuilder connStringBuilder;
|
||||
try
|
||||
{
|
||||
// set connection string using connection uri if connection details are undefined
|
||||
if (connStringParams.ConnectionDetails == null)
|
||||
{
|
||||
TryFindConnection(connStringParams.OwnerUri, out info);
|
||||
connStringBuilder = CreateConnectionStringBuilder(info.ConnectionDetails);
|
||||
}
|
||||
// set connection string using connection details
|
||||
else
|
||||
{
|
||||
connStringBuilder = CreateConnectionStringBuilder(connStringParams.ConnectionDetails as ConnectionDetails);
|
||||
}
|
||||
if (!connStringParams.IncludePassword)
|
||||
{
|
||||
connStringBuilder.Password = ConnectionService.PasswordPlaceholder;
|
||||
}
|
||||
// default connection string application name to always be included unless set to false
|
||||
if (!connStringParams.IncludeApplicationName.HasValue || connStringParams.IncludeApplicationName.Value == true)
|
||||
{
|
||||
connStringBuilder.ApplicationName = "sqlops-connection-string";
|
||||
}
|
||||
connectionString = connStringBuilder.ConnectionString;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
try
|
||||
{
|
||||
SqlConnectionStringBuilder connStringBuilder = CreateConnectionStringBuilder(info.ConnectionDetails);
|
||||
|
||||
if (!connStringParams.IncludePassword)
|
||||
{
|
||||
connStringBuilder.Password = ConnectionService.PasswordPlaceholder;
|
||||
}
|
||||
// default connection string application name to always be included unless set to false
|
||||
if (!connStringParams.IncludeApplicationName.HasValue || connStringParams.IncludeApplicationName.Value == true)
|
||||
{
|
||||
connStringBuilder.ApplicationName = "sqlops-connection-string";
|
||||
}
|
||||
connectionString = connStringBuilder.ConnectionString;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
|
||||
await requestContext.SendResult(connectionString);
|
||||
|
||||
@@ -15,6 +15,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
||||
/// </summary>
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Connection information of the connection
|
||||
/// </summary>
|
||||
public ConnectionDetails ConnectionDetails { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the password should be return in the connection string
|
||||
/// default is set to false
|
||||
@@ -25,6 +30,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
||||
/// Indicates whether the application name should be return in the connection string
|
||||
/// default is set to true
|
||||
/// </summary>
|
||||
public bool? IncludeApplicationName { get; set;}
|
||||
public bool? IncludeApplicationName { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user