-
Notifications
You must be signed in to change notification settings - Fork 368
/
MsSqlKernelConnector.cs
53 lines (40 loc) · 1.6 KB
/
MsSqlKernelConnector.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Threading.Tasks;
using Microsoft.DotNet.Interactive.Connection;
namespace Microsoft.DotNet.Interactive.SqlServer;
public class MsSqlKernelConnector : IKernelConnector
{
public MsSqlKernelConnector(bool createDbContext, string connectionString)
{
CreateDbContext = createDbContext;
ConnectionString = connectionString;
}
public bool CreateDbContext { get; }
public string ConnectionString { get; }
public string PathToService { get; set; }
public async Task<Kernel> CreateKernelAsync(string kernelName)
{
if (string.IsNullOrWhiteSpace(PathToService))
{
throw new InvalidOperationException($"{nameof(PathToService)} cannot be null or whitespace.");
}
var serviceArgs = $"--parent-pid {Environment.ProcessId}";
var logFile = Environment.GetEnvironmentVariable("DOTNET_SQLTOOLSSERVICE_LOGFILE");
if (!string.IsNullOrWhiteSpace(logFile))
{
var logArgs = $" --log-file \"{logFile}\" --tracing-level Verbose";
serviceArgs += logArgs;
}
var client = new ToolsServiceClient(PathToService, serviceArgs);
var kernel = new MsSqlKernel(
$"sql-{kernelName}",
ConnectionString,
client)
.UseValueSharing();
kernel.RegisterForDisposal(client);
await kernel.ConnectAsync();
return kernel;
}
}