mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
Update docs (#200)
This is a documentation-only update so automerging. Please review the commit if there are any follow-ups requested. * Update .gitignore for docfx genertated files * Update documenation (part 1) * Update docs and add some samples * More doc updates
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -282,6 +282,10 @@ Session.vim
|
||||
# Visual Studio Code
|
||||
.vscode/
|
||||
|
||||
# docfx generated files
|
||||
_site
|
||||
metadata
|
||||
|
||||
# Stuff from cake
|
||||
/artifacts/
|
||||
/.tools/
|
||||
|
||||
11
docs/design/index.md
Normal file
11
docs/design/index.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Design and Implementation
|
||||
|
||||
Design and implementation notes.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
@@ -33,6 +33,7 @@
|
||||
"toc.yml",
|
||||
"index.md",
|
||||
"api/index.md",
|
||||
"design/index.md",
|
||||
"guide/**.md"
|
||||
],
|
||||
"exclude": [
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
# [Introduction](introduction.md)
|
||||
# [Using the JSON-RPC API](using_the_host_process.md)
|
||||
# [Using the .NET API](using_the_dotnet_api.md)
|
||||
@@ -1,4 +1,66 @@
|
||||
# Using the SQL Tools Service .NET API
|
||||
|
||||
> NOTE: This page will eventually provide usage examples of the .NET
|
||||
> API. For now the [API Reference](../api/index.md) is the best starting point.
|
||||
> NOTE: The [API Reference](../api/index.md) is the best starting point for working directly with
|
||||
> the .NET API.
|
||||
|
||||
An example of using the JSON RPC API from a .Net Core console application is available at docs/samples/jsonrpc/netcore.
|
||||
The following snippet provides a basic example of how to connect to a database and execute a query.
|
||||
|
||||
```typescript
|
||||
internal static async Task ExecuteQuery(string query)
|
||||
{
|
||||
// create a temporary "workspace" file
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
// create the client helper which wraps the client driver objects
|
||||
using (ClientHelper testHelper = new ClientHelper())
|
||||
{
|
||||
// connnection details
|
||||
ConnectParams connectParams = new ConnectParams();
|
||||
connectParams.Connection = new ConnectionDetails();
|
||||
connectParams.Connection.ServerName = "localhost";
|
||||
connectParams.Connection.DatabaseName = "master";
|
||||
connectParams.Connection.AuthenticationType = "Integrated";
|
||||
|
||||
// connect to the database
|
||||
await testHelper.Connect(queryTempFile.FilePath, connectParams);
|
||||
|
||||
// execute the query
|
||||
QueryExecuteCompleteParams queryComplete =
|
||||
await testHelper.RunQuery(queryTempFile.FilePath, query);
|
||||
|
||||
if (queryComplete.BatchSummaries != null && queryComplete.BatchSummaries.Length > 0)
|
||||
{
|
||||
var batch = queryComplete.BatchSummaries[0];
|
||||
if (batch.ResultSetSummaries != null && batch.ResultSetSummaries.Length > 0)
|
||||
{
|
||||
var resultSet = batch.ResultSetSummaries[0];
|
||||
|
||||
// retrive the results
|
||||
QueryExecuteSubsetResult querySubset = await testHelper.ExecuteSubset(
|
||||
queryTempFile.FilePath, batch.Id,
|
||||
resultSet.Id, 0, (int)resultSet.RowCount);
|
||||
|
||||
// print the header
|
||||
foreach (var column in resultSet.ColumnInfo)
|
||||
{
|
||||
Console.Write(column.ColumnName + ", ");
|
||||
}
|
||||
Console.Write(Environment.NewLine);
|
||||
|
||||
// print the rows
|
||||
foreach (var row in querySubset.ResultSubset.Rows)
|
||||
{
|
||||
for (int i = 0; i < resultSet.ColumnInfo.Length; ++i)
|
||||
{
|
||||
Console.Write(row.GetValue(i) + ", ");
|
||||
}
|
||||
Console.Write(Environment.NewLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// close database connection
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
1419
docs/guide/using_the_host_process.md
Normal file
1419
docs/guide/using_the_host_process.md
Normal file
File diff suppressed because it is too large
Load Diff
BIN
docs/images/connected_bind.png
Normal file
BIN
docs/images/connected_bind.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 200 KiB |
BIN
docs/images/hostprocess.png
Normal file
BIN
docs/images/hostprocess.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 204 KiB |
BIN
docs/images/msgdispatch.png
Normal file
BIN
docs/images/msgdispatch.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 65 KiB |
BIN
docs/images/msgdispatchexample.png
Normal file
BIN
docs/images/msgdispatchexample.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
@@ -9,7 +9,11 @@ guidance on how to use it.
|
||||
|
||||
## [API Reference](api/index.md)
|
||||
|
||||
The API Reference contains details about the .NET API.
|
||||
The .Net API Reference contains details about the .NET API.
|
||||
|
||||
## [Design](design/index.md)
|
||||
|
||||
Design and implementation documentation for the SQL Tools Service SDK.
|
||||
|
||||
## Getting Help
|
||||
|
||||
|
||||
102
docs/samples/jsonrpc/netcore/executequery/Driver/ClientDriver.cs
Normal file
102
docs/samples/jsonrpc/netcore/executequery/Driver/ClientDriver.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Channel;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.JsonRpc.Driver
|
||||
{
|
||||
/// <summary>
|
||||
/// Test driver for the service host
|
||||
/// </summary>
|
||||
public class ClientDriver : ClientDriverBase
|
||||
{
|
||||
public const string ServiceHostEnvironmentVariable = "SQLTOOLSSERVICE_EXE";
|
||||
|
||||
|
||||
private Process[] serviceProcesses;
|
||||
|
||||
private DateTime startTime;
|
||||
|
||||
public ClientDriver()
|
||||
{
|
||||
string serviceHostExecutable = Environment.GetEnvironmentVariable(ServiceHostEnvironmentVariable);
|
||||
string serviceHostArguments = "--enable-logging";
|
||||
if (string.IsNullOrWhiteSpace(serviceHostExecutable))
|
||||
{
|
||||
// Include a fallback value to for running tests within visual studio
|
||||
serviceHostExecutable = @"Microsoft.SqlTools.ServiceLayer.exe";
|
||||
}
|
||||
|
||||
// Make sure it exists before continuing
|
||||
if (!File.Exists(serviceHostExecutable))
|
||||
{
|
||||
throw new FileNotFoundException($"Failed to find Microsoft.SqlTools.ServiceLayer.exe at provided location '{serviceHostExecutable}'. " +
|
||||
"Please set SQLTOOLSERVICE_EXE environment variable to location of exe");
|
||||
}
|
||||
|
||||
this.clientChannel = new StdioClientChannel(serviceHostExecutable, serviceHostArguments);
|
||||
this.protocolClient = new ProtocolEndpoint(clientChannel, MessageProtocolType.LanguageServer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start the test driver, and launch the sqltoolsservice executable
|
||||
/// </summary>
|
||||
public async Task Start()
|
||||
{
|
||||
// Store the time we started
|
||||
startTime = DateTime.Now;
|
||||
|
||||
// Launch the process
|
||||
await this.protocolClient.Start();
|
||||
await Task.Delay(1000); // Wait for the service host to start
|
||||
|
||||
Console.WriteLine("Successfully launched service");
|
||||
|
||||
// Setup events to queue for testing
|
||||
this.QueueEventsForType(ConnectionCompleteNotification.Type);
|
||||
this.QueueEventsForType(IntelliSenseReadyNotification.Type);
|
||||
this.QueueEventsForType(QueryExecuteCompleteEvent.Type);
|
||||
this.QueueEventsForType(PublishDiagnosticsNotification.Type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop the test driver, and shutdown the sqltoolsservice executable
|
||||
/// </summary>
|
||||
public async Task Stop()
|
||||
{
|
||||
|
||||
await this.protocolClient.Stop();
|
||||
}
|
||||
|
||||
private async Task GetServiceProcess(CancellationToken token)
|
||||
{
|
||||
while (serviceProcesses == null && !token.IsCancellationRequested)
|
||||
{
|
||||
var processes = Process.GetProcessesByName("Microsoft.SqlTools.ServiceLayer")
|
||||
.Where(p => p.StartTime >= startTime).ToArray();
|
||||
|
||||
// Wait a second if we can't find the process
|
||||
if (processes.Any())
|
||||
{
|
||||
serviceProcesses = processes;
|
||||
}
|
||||
else
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(1), token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Channel;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.JsonRpc.Driver
|
||||
{
|
||||
/// <summary>
|
||||
/// Wraps the ProtocolEndpoint class with queues to handle events/requests
|
||||
/// </summary>
|
||||
public class ClientDriverBase
|
||||
{
|
||||
protected ProtocolEndpoint protocolClient;
|
||||
|
||||
protected StdioClientChannel clientChannel;
|
||||
|
||||
private ConcurrentDictionary<string, AsyncQueue<object>> eventQueuePerType =
|
||||
new ConcurrentDictionary<string, AsyncQueue<object>>();
|
||||
|
||||
private ConcurrentDictionary<string, AsyncQueue<object>> requestQueuePerType =
|
||||
new ConcurrentDictionary<string, AsyncQueue<object>>();
|
||||
|
||||
public Process ServiceProcess
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return Process.GetProcessById(clientChannel.ProcessId);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Task<TResult> SendRequest<TParams, TResult>(
|
||||
RequestType<TParams, TResult> requestType,
|
||||
TParams requestParams)
|
||||
{
|
||||
return
|
||||
this.protocolClient.SendRequest(
|
||||
requestType,
|
||||
requestParams);
|
||||
}
|
||||
|
||||
public Task SendEvent<TParams>(EventType<TParams> eventType, TParams eventParams)
|
||||
{
|
||||
return
|
||||
this.protocolClient.SendEvent(
|
||||
eventType,
|
||||
eventParams);
|
||||
}
|
||||
|
||||
public void QueueEventsForType<TParams>(EventType<TParams> eventType)
|
||||
{
|
||||
var eventQueue =
|
||||
this.eventQueuePerType.AddOrUpdate(
|
||||
eventType.MethodName,
|
||||
new AsyncQueue<object>(),
|
||||
(key, queue) => queue);
|
||||
|
||||
this.protocolClient.SetEventHandler(
|
||||
eventType,
|
||||
(p, ctx) =>
|
||||
{
|
||||
return eventQueue.EnqueueAsync(p);
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<TParams> WaitForEvent<TParams>(
|
||||
EventType<TParams> eventType,
|
||||
int timeoutMilliseconds = 5000)
|
||||
{
|
||||
Task<TParams> eventTask = null;
|
||||
|
||||
// Use the event queue if one has been registered
|
||||
AsyncQueue<object> eventQueue = null;
|
||||
if (this.eventQueuePerType.TryGetValue(eventType.MethodName, out eventQueue))
|
||||
{
|
||||
eventTask =
|
||||
eventQueue
|
||||
.DequeueAsync()
|
||||
.ContinueWith<TParams>(
|
||||
task => (TParams)task.Result);
|
||||
}
|
||||
else
|
||||
{
|
||||
TaskCompletionSource<TParams> eventTaskSource = new TaskCompletionSource<TParams>();
|
||||
|
||||
this.protocolClient.SetEventHandler(
|
||||
eventType,
|
||||
(p, ctx) =>
|
||||
{
|
||||
if (!eventTaskSource.Task.IsCompleted)
|
||||
{
|
||||
eventTaskSource.SetResult(p);
|
||||
}
|
||||
|
||||
return Task.FromResult(true);
|
||||
},
|
||||
true); // Override any existing handler
|
||||
|
||||
eventTask = eventTaskSource.Task;
|
||||
}
|
||||
|
||||
await
|
||||
Task.WhenAny(
|
||||
eventTask,
|
||||
Task.Delay(timeoutMilliseconds));
|
||||
|
||||
if (!eventTask.IsCompleted)
|
||||
{
|
||||
throw new TimeoutException(
|
||||
string.Format(
|
||||
"Timed out waiting for '{0}' event!",
|
||||
eventType.MethodName));
|
||||
}
|
||||
|
||||
return await eventTask;
|
||||
}
|
||||
|
||||
public async Task<Tuple<TParams, RequestContext<TResponse>>> WaitForRequest<TParams, TResponse>(
|
||||
RequestType<TParams, TResponse> requestType,
|
||||
int timeoutMilliseconds = 5000)
|
||||
{
|
||||
Task<Tuple<TParams, RequestContext<TResponse>>> requestTask = null;
|
||||
|
||||
// Use the request queue if one has been registered
|
||||
AsyncQueue<object> requestQueue = null;
|
||||
if (this.requestQueuePerType.TryGetValue(requestType.MethodName, out requestQueue))
|
||||
{
|
||||
requestTask =
|
||||
requestQueue
|
||||
.DequeueAsync()
|
||||
.ContinueWith(
|
||||
task => (Tuple<TParams, RequestContext<TResponse>>)task.Result);
|
||||
}
|
||||
else
|
||||
{
|
||||
var requestTaskSource =
|
||||
new TaskCompletionSource<Tuple<TParams, RequestContext<TResponse>>>();
|
||||
|
||||
this.protocolClient.SetRequestHandler(
|
||||
requestType,
|
||||
(p, ctx) =>
|
||||
{
|
||||
if (!requestTaskSource.Task.IsCompleted)
|
||||
{
|
||||
requestTaskSource.SetResult(
|
||||
new Tuple<TParams, RequestContext<TResponse>>(p, ctx));
|
||||
}
|
||||
|
||||
return Task.FromResult(true);
|
||||
});
|
||||
|
||||
requestTask = requestTaskSource.Task;
|
||||
}
|
||||
|
||||
await
|
||||
Task.WhenAny(
|
||||
requestTask,
|
||||
Task.Delay(timeoutMilliseconds));
|
||||
|
||||
if (!requestTask.IsCompleted)
|
||||
{
|
||||
throw new TimeoutException(
|
||||
string.Format(
|
||||
"Timed out waiting for '{0}' request!",
|
||||
requestType.MethodName));
|
||||
}
|
||||
|
||||
return await requestTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
85
docs/samples/jsonrpc/netcore/executequery/Program.cs
Normal file
85
docs/samples/jsonrpc/netcore/executequery/Program.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. 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.SqlTools.JsonRpc.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.JsonRpc.ExecuteQuery
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple JSON-RPC API sample to connect to a database, execute a query, and print the results
|
||||
/// </summary>
|
||||
internal class Program
|
||||
{
|
||||
internal static void Main(string[] args)
|
||||
{
|
||||
// set SQLTOOLSSERVICE_EXE to location of SQL Tools Service executable
|
||||
Environment.SetEnvironmentVariable("SQLTOOLSSERVICE_EXE", @"Microsoft.SqlTools.ServiceLayer.exe");
|
||||
|
||||
// execute a query against localhost, master, with IntegratedAuth
|
||||
ExecuteQuery("SELECT * FROM sys.objects").Wait();
|
||||
}
|
||||
|
||||
internal static async Task ExecuteQuery(string query)
|
||||
{
|
||||
// create a temporary "workspace" file
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
// create the client helper which wraps the client driver objects
|
||||
using (ClientHelper testHelper = new ClientHelper())
|
||||
{
|
||||
// connnection details
|
||||
ConnectParams connectParams = new ConnectParams();
|
||||
connectParams.Connection = new ConnectionDetails();
|
||||
connectParams.Connection.ServerName = "localhost";
|
||||
connectParams.Connection.DatabaseName = "master";
|
||||
connectParams.Connection.AuthenticationType = "Integrated";
|
||||
|
||||
// connect to the database
|
||||
await testHelper.Connect(queryTempFile.FilePath, connectParams);
|
||||
|
||||
// execute the query
|
||||
QueryExecuteCompleteParams queryComplete =
|
||||
await testHelper.RunQuery(queryTempFile.FilePath, query);
|
||||
|
||||
if (queryComplete.BatchSummaries != null && queryComplete.BatchSummaries.Length > 0)
|
||||
{
|
||||
var batch = queryComplete.BatchSummaries[0];
|
||||
if (batch.ResultSetSummaries != null && batch.ResultSetSummaries.Length > 0)
|
||||
{
|
||||
var resultSet = batch.ResultSetSummaries[0];
|
||||
|
||||
// retrive the results
|
||||
QueryExecuteSubsetResult querySubset = await testHelper.ExecuteSubset(
|
||||
queryTempFile.FilePath, batch.Id,
|
||||
resultSet.Id, 0, (int)resultSet.RowCount);
|
||||
|
||||
// print the header
|
||||
foreach (var column in resultSet.ColumnInfo)
|
||||
{
|
||||
Console.Write(column.ColumnName + ", ");
|
||||
}
|
||||
Console.Write(Environment.NewLine);
|
||||
|
||||
// print the rows
|
||||
foreach (var row in querySubset.ResultSubset.Rows)
|
||||
{
|
||||
for (int i = 0; i < resultSet.ColumnInfo.Length; ++i)
|
||||
{
|
||||
Console.Write(row.GetValue(i) + ", ");
|
||||
}
|
||||
Console.Write(Environment.NewLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// close database connection
|
||||
await testHelper.Disconnect(queryTempFile.FilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.JsonRpc.Driver;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Credentials.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.JsonRpc.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for all test suites run by the test driver
|
||||
/// </summary>
|
||||
public sealed class ClientHelper : IDisposable
|
||||
{
|
||||
private bool isRunning = false;
|
||||
|
||||
public ClientHelper()
|
||||
{
|
||||
Driver = new ClientDriver();
|
||||
Driver.Start().Wait();
|
||||
this.isRunning = true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (this.isRunning)
|
||||
{
|
||||
WaitForExit();
|
||||
}
|
||||
}
|
||||
|
||||
public void WaitForExit()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.isRunning = false;
|
||||
Driver.Stop().Wait();
|
||||
Console.WriteLine("Successfully killed process.");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine($"Exception while waiting for service exit: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The driver object used to read/write data to the service
|
||||
/// </summary>
|
||||
public ClientDriver Driver
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
private object fileLock = new Object();
|
||||
|
||||
/// <summary>
|
||||
/// Request a new connection to be created
|
||||
/// </summary>
|
||||
/// <returns>True if the connection completed successfully</returns>
|
||||
public async Task<bool> Connect(string ownerUri, ConnectParams connectParams, int timeout = 15000)
|
||||
{
|
||||
connectParams.OwnerUri = ownerUri;
|
||||
var connectResult = await Driver.SendRequest(ConnectionRequest.Type, connectParams);
|
||||
if (connectResult)
|
||||
{
|
||||
var completeEvent = await Driver.WaitForEvent(ConnectionCompleteNotification.Type, timeout);
|
||||
return !string.IsNullOrEmpty(completeEvent.ConnectionId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a disconnect
|
||||
/// </summary>
|
||||
public async Task<bool> Disconnect(string ownerUri)
|
||||
{
|
||||
var disconnectParams = new DisconnectParams();
|
||||
disconnectParams.OwnerUri = ownerUri;
|
||||
|
||||
var disconnectResult = await Driver.SendRequest(DisconnectRequest.Type, disconnectParams);
|
||||
return disconnectResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a cancel connect
|
||||
/// </summary>
|
||||
public async Task<bool> CancelConnect(string ownerUri)
|
||||
{
|
||||
var cancelParams = new CancelConnectParams();
|
||||
cancelParams.OwnerUri = ownerUri;
|
||||
|
||||
return await Driver.SendRequest(CancelConnectRequest.Type, cancelParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a cancel connect
|
||||
/// </summary>
|
||||
public async Task<ListDatabasesResponse> ListDatabases(string ownerUri)
|
||||
{
|
||||
var listParams = new ListDatabasesParams();
|
||||
listParams.OwnerUri = ownerUri;
|
||||
|
||||
return await Driver.SendRequest(ListDatabasesRequest.Type, listParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request the active SQL script is parsed for errors
|
||||
/// </summary>
|
||||
public async Task<QueryExecuteSubsetResult> RequestQueryExecuteSubset(QueryExecuteSubsetParams subsetParams)
|
||||
{
|
||||
return await Driver.SendRequest(QueryExecuteSubsetRequest.Type, subsetParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request the active SQL script is parsed for errors
|
||||
/// </summary>
|
||||
public async Task RequestOpenDocumentNotification(DidOpenTextDocumentNotification openParams)
|
||||
{
|
||||
await Driver.SendEvent(DidOpenTextDocumentNotification.Type, openParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a configuration change notification
|
||||
/// </summary>
|
||||
public async Task RequestChangeConfigurationNotification(DidChangeConfigurationParams<SqlToolsSettings> configParams)
|
||||
{
|
||||
await Driver.SendEvent(DidChangeConfigurationNotification<SqlToolsSettings>.Type, configParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// /// Request the active SQL script is parsed for errors
|
||||
/// </summary>
|
||||
public async Task RequestChangeTextDocumentNotification(DidChangeTextDocumentParams changeParams)
|
||||
{
|
||||
await Driver.SendEvent(DidChangeTextDocumentNotification.Type, changeParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request completion item resolve to look-up additional info
|
||||
/// </summary>
|
||||
public async Task<CompletionItem> RequestResolveCompletion(CompletionItem item)
|
||||
{
|
||||
var result = await Driver.SendRequest(CompletionResolveRequest.Type, item);
|
||||
return result;
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// Request a Read Credential for given credential id
|
||||
// /// </summary>
|
||||
// public async Task<Credential> ReadCredential(string credentialId)
|
||||
// {
|
||||
// var credentialParams = new Credential();
|
||||
// credentialParams.CredentialId = credentialId;
|
||||
|
||||
// return await Driver.SendRequest(ReadCredentialRequest.Type, credentialParams);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Run a query using a given connection bound to a URI
|
||||
/// </summary>
|
||||
public async Task<QueryExecuteCompleteParams> RunQuery(string ownerUri, string query, int timeoutMilliseconds = 5000)
|
||||
{
|
||||
// Write the query text to a backing file
|
||||
WriteToFile(ownerUri, query);
|
||||
|
||||
var queryParams = new QueryExecuteParams
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
QuerySelection = null
|
||||
};
|
||||
|
||||
var result = await Driver.SendRequest(QueryExecuteRequest.Type, queryParams);
|
||||
if (result != null && string.IsNullOrEmpty(result.Messages))
|
||||
{
|
||||
var eventResult = await Driver.WaitForEvent(QueryExecuteCompleteEvent.Type, timeoutMilliseconds);
|
||||
return eventResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request to save query results as CSV
|
||||
/// </summary>
|
||||
public async Task<SaveResultRequestResult> SaveAsCsv(string ownerUri, string filename, int batchIndex, int resultSetIndex)
|
||||
{
|
||||
var saveParams = new SaveResultsAsCsvRequestParams
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
BatchIndex = batchIndex,
|
||||
ResultSetIndex = resultSetIndex,
|
||||
FilePath = filename
|
||||
};
|
||||
|
||||
var result = await Driver.SendRequest(SaveResultsAsCsvRequest.Type, saveParams);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request to save query results as JSON
|
||||
/// </summary>
|
||||
public async Task<SaveResultRequestResult> SaveAsJson(string ownerUri, string filename, int batchIndex, int resultSetIndex)
|
||||
{
|
||||
var saveParams = new SaveResultsAsJsonRequestParams
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
BatchIndex = batchIndex,
|
||||
ResultSetIndex = resultSetIndex,
|
||||
FilePath = filename
|
||||
};
|
||||
|
||||
var result = await Driver.SendRequest(SaveResultsAsJsonRequest.Type, saveParams);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a subset of results from a query
|
||||
/// </summary>
|
||||
public async Task<QueryExecuteSubsetResult> ExecuteSubset(string ownerUri, int batchIndex, int resultSetIndex, int rowStartIndex, int rowCount)
|
||||
{
|
||||
var subsetParams = new QueryExecuteSubsetParams();
|
||||
subsetParams.OwnerUri = ownerUri;
|
||||
subsetParams.BatchIndex = batchIndex;
|
||||
subsetParams.ResultSetIndex = resultSetIndex;
|
||||
subsetParams.RowsStartIndex = rowStartIndex;
|
||||
subsetParams.RowsCount = rowCount;
|
||||
|
||||
var result = await Driver.SendRequest(QueryExecuteSubsetRequest.Type, subsetParams);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void WriteToFile(string ownerUri, string query)
|
||||
{
|
||||
lock (fileLock)
|
||||
{
|
||||
System.IO.File.WriteAllText(ownerUri, query);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Microsoft.SqlTools.JsonRpc.Utility
|
||||
{
|
||||
public class SelfCleaningTempFile : IDisposable
|
||||
{
|
||||
private bool disposed;
|
||||
|
||||
public SelfCleaningTempFile()
|
||||
{
|
||||
FilePath = Path.GetTempFileName();
|
||||
}
|
||||
|
||||
public string FilePath { get; private set; }
|
||||
|
||||
#region IDisposable Implementation
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed && disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(FilePath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine($"Failed to cleanup {FilePath}");
|
||||
}
|
||||
}
|
||||
|
||||
disposed = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
49
docs/samples/jsonrpc/netcore/executequery/project.json
Normal file
49
docs/samples/jsonrpc/netcore/executequery/project.json
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "Microsoft.SqlTools.JsonRpcTest.ExecuteQuery",
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.SqlTools.ServiceLayer": {
|
||||
"target": "project"
|
||||
},
|
||||
"Newtonsoft.Json": "9.0.1",
|
||||
"System.Data.Common": "4.1.0",
|
||||
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
||||
"Microsoft.SqlServer.Smo": "140.1.12",
|
||||
"System.Security.SecureString": "4.0.0",
|
||||
"System.Collections.Specialized": "4.0.1",
|
||||
"System.ComponentModel.TypeConverter": "4.1.0",
|
||||
"System.Diagnostics.Contracts": "4.0.1",
|
||||
"System.Diagnostics.TraceSource": "4.0.0",
|
||||
"NETStandard.Library": "1.6.0",
|
||||
"Microsoft.NETCore.Runtime.CoreCLR": "1.0.2",
|
||||
"Microsoft.NETCore.DotNetHostPolicy": "1.0.1",
|
||||
"System.Diagnostics.Process": "4.1.0",
|
||||
"System.Threading.Thread": "4.0.0"
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"version": "1.0.0"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
},
|
||||
"runtimes": {
|
||||
"win7-x64": {},
|
||||
"win7-x86": {},
|
||||
"osx.10.11-x64": {},
|
||||
"ubuntu.14.04-x64": {},
|
||||
"ubuntu.16.04-x64": {},
|
||||
"centos.7-x64": {},
|
||||
"rhel.7.2-x64": {},
|
||||
"debian.8-x64": {},
|
||||
"fedora.23-x64": {},
|
||||
"opensuse.13.2-x64": {}
|
||||
}
|
||||
}
|
||||
28
docs/samples/smo/PowerShellScript/createxmlshema.ps1
Normal file
28
docs/samples/smo/PowerShellScript/createxmlshema.ps1
Normal file
@@ -0,0 +1,28 @@
|
||||
<#
|
||||
This code example shows how to create an XML schema by using the XmlSchemaCollection object.
|
||||
#>
|
||||
|
||||
#DLL location needs to be specified
|
||||
$pathtodll = ""
|
||||
Add-Type -Path "$pathtodll\Microsoft.SqlServer.Smo.dll"
|
||||
Add-Type -Path "$pathtodll\Microsoft.SqlServer.ConnectionInfo.dll"
|
||||
|
||||
#Connection context need to be specified
|
||||
$srv = New-Object Microsoft.SqlServer.Management.Smo.Server()
|
||||
$srv.ConnectionContext.LoginSecure = $false
|
||||
$srv.ConnectionContext.ServerInstance = "instance_name"
|
||||
$srv.ConnectionContext.Login = "user_id"
|
||||
$srv.ConnectionContext.Password = "pwd"
|
||||
|
||||
#Reference the master database
|
||||
$db = $srv.Databases["master"]
|
||||
|
||||
#Create a new schema collection
|
||||
$xsc = New-Object -TypeName Microsoft.SqlServer.Management.SMO.XmlSchemaCollection -argumentlist $db,"SampleCollection"
|
||||
|
||||
#Add the xml
|
||||
$dq = '"' # the double quote character
|
||||
$xsc.Text = "<schema xmlns=" + $dq + "http://www.w3.org/2001/XMLSchema" + $dq + " xmlns:ns=" + $dq + "http://ns" + $dq + "><element name=" + $dq + "e" + $dq + " type=" + $dq + "dateTime" + $dq + "/></schema>"
|
||||
|
||||
#Create the XML schema collection on the instance of SQL Server.
|
||||
$xsc.Create
|
||||
27
docs/samples/smo/PowerShellScript/dbiteration.ps1
Normal file
27
docs/samples/smo/PowerShellScript/dbiteration.ps1
Normal file
@@ -0,0 +1,27 @@
|
||||
<#
|
||||
This script demonstrates iterations through the rows and display collation details for a remote or local instance of SQL Server.
|
||||
#>
|
||||
|
||||
#DLL location needs to be specified
|
||||
$pathtodll = ""
|
||||
|
||||
Add-Type -Path "$pathtodll\Microsoft.SqlServer.Smo.dll"
|
||||
Add-Type -Path "$pathtodll\Microsoft.SqlServer.ConnectionInfo.dll"
|
||||
|
||||
#Connection context need to be specified
|
||||
$srv = New-Object Microsoft.SqlServer.Management.Smo.Server()
|
||||
$srv.ConnectionContext.LoginSecure = $false
|
||||
$srv.ConnectionContext.ServerInstance = "instance_name"
|
||||
$srv.ConnectionContext.Login = "user_id"
|
||||
$srv.ConnectionContext.Password = "pwd"
|
||||
|
||||
$datatable = $srv.EnumCollations()
|
||||
|
||||
Foreach ($row in $datatable.Rows)
|
||||
{
|
||||
Write-Host "============================================"
|
||||
Foreach ($column in $row.Table.Columns)
|
||||
{
|
||||
Write-Host $column.ColumnName "=" $row[$column].ToString()
|
||||
}
|
||||
}
|
||||
58
docs/samples/smo/PowerShellScript/managetable.ps1
Normal file
58
docs/samples/smo/PowerShellScript/managetable.ps1
Normal file
@@ -0,0 +1,58 @@
|
||||
<#
|
||||
This code example creates a table that has several columns with different types and purposes. The code also provides examples of how to create an identity field, how to create a primary key, and how to alter table properties.
|
||||
#>
|
||||
|
||||
#DLL location needs to be specified
|
||||
$pathtodll = ""
|
||||
Add-Type -Path "$pathtodll\Microsoft.SqlServer.Smo.dll"
|
||||
Add-Type -Path "$pathtodll\Microsoft.SqlServer.ConnectionInfo.dll"
|
||||
|
||||
#Connection context need to be specified
|
||||
$srv = New-Object Microsoft.SqlServer.Management.Smo.Server()
|
||||
$srv.ConnectionContext.LoginSecure = $false
|
||||
$srv.ConnectionContext.ServerInstance = "instance_name"
|
||||
$srv.ConnectionContext.Login = "user_id"
|
||||
$srv.ConnectionContext.Password = "pwd"
|
||||
|
||||
#And the database object corresponding to master.
|
||||
$db = $srv.Databases["master"]
|
||||
|
||||
#Create a SMO Table
|
||||
$tb = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Table -argumentlist $db, "Test_Table"
|
||||
|
||||
#Add various columns to the table.
|
||||
$Type = [Microsoft.SqlServer.Management.SMO.DataType]::NChar(50)
|
||||
$col1 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Column -argumentlist $tb,"Name", $Type
|
||||
$col1.Collation = "Latin1_General_CI_AS"
|
||||
$col1.Nullable = $true
|
||||
$tb.Columns.Add($col1)
|
||||
|
||||
$Type = [Microsoft.SqlServer.Management.SMO.DataType]::Int
|
||||
$col2 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Column -argumentlist $tb,"ID", $Type
|
||||
$col2.Identity = $true
|
||||
$col2.IdentitySeed = 1
|
||||
$col2.IdentityIncrement = 1
|
||||
$tb.Columns.Add($col2)
|
||||
|
||||
$Type = [Microsoft.SqlServer.Management.SMO.DataType]::Real
|
||||
$col3 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Column -argumentlist $tb,"Value", $Type
|
||||
$tb.Columns.Add($col3)
|
||||
|
||||
$Type = [Microsoft.SqlServer.Management.SMO.DataType]::DateTime
|
||||
$col4 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Column -argumentlist $tb,"Date", $Type
|
||||
$col4.Nullable = $false
|
||||
$tb.Columns.Add($col4)
|
||||
|
||||
#Create the table
|
||||
$tb.Create()
|
||||
|
||||
$Type = [Microsoft.SqlServer.Management.SMO.DataType]::DateTime
|
||||
$col5 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Column -argumentlist $tb,"ExpiryDate", $Type
|
||||
$col5.Nullable = $false
|
||||
$tb.Columns.Add($col5)
|
||||
|
||||
#Run the Alter method to make the change on the instance of SQL Server.
|
||||
$tb.Alter()
|
||||
|
||||
#Remove the table from the database.
|
||||
$tb.Drop()
|
||||
45
docs/samples/smo/net45/Scripting/Program.cs
Normal file
45
docs/samples/smo/net45/Scripting/Program.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
|
||||
namespace Microsoft.SqlServer.Management.SmoSdkSamples
|
||||
{
|
||||
// This application demonstrates how to script out a sample database without dependencies and iterate through the list to display the results.
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// Connect to the local, default instance of SQL Server.
|
||||
Smo.Server srv = new Smo.Server();
|
||||
// database name
|
||||
Console.WriteLine("Enter database name for scripting:");
|
||||
string dbName = Console.ReadLine();
|
||||
// Reference the database.
|
||||
Database db = srv.Databases[dbName];
|
||||
// Define a Scripter object and set the required scripting options.
|
||||
Scripter scripter = new Scripter(srv);
|
||||
scripter.Options.ScriptDrops = false;
|
||||
// To include indexes
|
||||
scripter.Options.Indexes = true;
|
||||
// to include referential constraints in the script
|
||||
scripter.Options.DriAllConstraints = true;
|
||||
// Iterate through the tables in database and script each one. Display the script.
|
||||
foreach (Table tb in db.Tables)
|
||||
{
|
||||
// check if the table is not a system table
|
||||
if (tb.IsSystemObject == false)
|
||||
{
|
||||
Console.WriteLine("-- Scripting for table " + tb.Name);
|
||||
// Generating script for table tb
|
||||
System.Collections.Specialized.StringCollection sc = scripter.Script(new Urn[] { tb.Urn });
|
||||
foreach (string st in sc)
|
||||
{
|
||||
Console.WriteLine(st);
|
||||
}
|
||||
Console.WriteLine("--");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
66
docs/samples/smo/net45/Scripting/Scripting.csproj
Normal file
66
docs/samples/smo/net45/Scripting/Scripting.csproj
Normal file
@@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{C0CACFBB-FDAF-4B3D-B9F7-EBC3179A5055}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Microsoft.SqlServer.Management.SmoSdkSamples</RootNamespace>
|
||||
<AssemblyName>SmoSdkSamples</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.SqlServer.Management.Sdk.Sfc, Version=14.000.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\SharedManagementObjects.140.1.9\lib\net40\Microsoft.SqlServer.Management.Sdk.Sfc.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.SqlServer.Smo, Version=14.000.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\SharedManagementObjects.140.1.9\lib\net40\Microsoft.SqlServer.Smo.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.SqlServer.SmoExtended, Version=14.000.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\SharedManagementObjects.140.1.9\lib\net40\Microsoft.SqlServer.SmoExtended.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
42
docs/samples/smo/netcore/ModifySetting/Program.cs
Normal file
42
docs/samples/smo/netcore/ModifySetting/Program.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Microsoft.Data.Tools.DataSets;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.SqlServer.Management.SmoSdkSamples
|
||||
{
|
||||
// This example displays information about the instance of SQL Server in Information and Settings, and modifies settings in Settings and UserOptionsobject properties.
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
//Connect to the local, default instance of SQL Server.
|
||||
Microsoft.SqlServer.Management.Smo.Server srv = new Microsoft.SqlServer.Management.Smo.Server();
|
||||
//Display all the configuration options.
|
||||
foreach (ConfigProperty p in srv.Configuration.Properties)
|
||||
{
|
||||
Console.WriteLine(p.DisplayName);
|
||||
}
|
||||
Console.WriteLine("There are " + srv.Configuration.Properties.Count.ToString() + " configuration options.");
|
||||
//Display the maximum and minimum values for ShowAdvancedOptions.
|
||||
int min = srv.Configuration.ShowAdvancedOptions.Minimum;
|
||||
int max = srv.Configuration.ShowAdvancedOptions.Maximum;
|
||||
Console.WriteLine("Minimum and Maximum values are " + min + " and " + max + ".");
|
||||
int configvalue = srv.Configuration.ShowAdvancedOptions.ConfigValue;
|
||||
//Modify the value of ShowAdvancedOptions and run the Alter method.
|
||||
srv.Configuration.ShowAdvancedOptions.ConfigValue = 0;
|
||||
srv.Configuration.Alter();
|
||||
//Display when the change takes place according to the IsDynamic property.
|
||||
if (srv.Configuration.ShowAdvancedOptions.IsDynamic == true)
|
||||
{
|
||||
Console.WriteLine("Configuration option has been updated.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Configuration option will be updated when SQL Server is restarted.");
|
||||
}
|
||||
// Recover setting value
|
||||
srv.Configuration.ShowAdvancedOptions.ConfigValue = configvalue;
|
||||
srv.Configuration.Alter();
|
||||
}
|
||||
}
|
||||
}
|
||||
21
docs/samples/smo/netcore/ModifySetting/project.json
Normal file
21
docs/samples/smo/netcore/ModifySetting/project.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.SqlServer.Smo": "140.1.12"
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,3 +3,7 @@
|
||||
homepage: guide/introduction.md
|
||||
- name: API Reference
|
||||
href: api/
|
||||
homepage: api/index.md
|
||||
- name: Design
|
||||
href: design/
|
||||
homepage: design/index.md
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
public delegate Task OnConnectionHandler(ConnectionInfo info);
|
||||
|
||||
/// <summary>
|
||||
// Callback for ondisconnect handler
|
||||
/// Callback for ondisconnect handler
|
||||
/// </summary>
|
||||
public delegate Task OnDisconnectHandler(ConnectionSummary summary, string ownerUri);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user