mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
3715 Default database name for Kusto (#1076)
* 3715 Refactored GetDatabaseName to load database names from kusto server when no database name available in connection string. * 3715 Removed variable name from GetDatabaseName
This commit is contained in:
@@ -86,8 +86,8 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource
|
|||||||
public KustoDataSource(string connectionString, string azureAccountToken)
|
public KustoDataSource(string connectionString, string azureAccountToken)
|
||||||
{
|
{
|
||||||
ClusterName = GetClusterName(connectionString);
|
ClusterName = GetClusterName(connectionString);
|
||||||
DatabaseName = GetDatabaseName(connectionString);
|
|
||||||
UserToken = azureAccountToken;
|
UserToken = azureAccountToken;
|
||||||
|
DatabaseName = GetDatabaseName(connectionString);
|
||||||
SchemaState = Task.Run(() =>
|
SchemaState = Task.Run(() =>
|
||||||
KustoIntellisenseHelper.AddOrUpdateDatabaseAsync(this, GlobalState.Default, DatabaseName, ClusterName,
|
KustoIntellisenseHelper.AddOrUpdateDatabaseAsync(this, GlobalState.Default, DatabaseName, ClusterName,
|
||||||
throwOnError: false)).Result;
|
throwOnError: false)).Result;
|
||||||
@@ -117,14 +117,31 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Extracts the database name from the connectionstring, if it exists
|
/// Extracts the database name from the connectionString if it exists
|
||||||
/// <summary>
|
/// otherwise it takes the first database name from the server
|
||||||
/// <param name="connectionString">A connection string coming over the Data management protocol</param>
|
/// </summary>
|
||||||
private static string GetDatabaseName(string connectionString)
|
/// <param name="connectionString"></param>
|
||||||
|
/// <returns>Database Name</returns>
|
||||||
|
private string GetDatabaseName(string connectionString)
|
||||||
{
|
{
|
||||||
var csb = new SqlConnectionStringBuilder(connectionString);
|
var csb = new SqlConnectionStringBuilder(connectionString);
|
||||||
|
|
||||||
return csb.InitialCatalog;
|
if (!string.IsNullOrWhiteSpace(csb.InitialCatalog))
|
||||||
|
{
|
||||||
|
return csb.InitialCatalog;
|
||||||
|
}
|
||||||
|
|
||||||
|
CancellationTokenSource source = new CancellationTokenSource();
|
||||||
|
CancellationToken token = source.Token;
|
||||||
|
|
||||||
|
string query = ".show databases | project DatabaseName";
|
||||||
|
|
||||||
|
using (var reader = ExecuteQuery(query, token))
|
||||||
|
{
|
||||||
|
var rows = reader.ToEnumerable();
|
||||||
|
var row = rows?.FirstOrDefault();
|
||||||
|
return row?[0].ToString() ?? string.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user