Show / Hide Table of Contents

# Class ConnectionService

Main class for the Connection Management services

##### Inheritance

System.Object
ConnectionService

##### Inherited Members

System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()

###### Namespace:Microsoft.SqlTools.ServiceLayer.Connection

###### Assembly:Microsoft.SqlTools.ServiceLayer.dll

##### Syntax

    public class ConnectionService

### Constructors

| Improve this Doc View Source

#### ConnectionService()

Default constructor should be private since it's a singleton class, but we need a constructor for use in unit test mocking.

##### Declaration

    public ConnectionService()

| Improve this Doc View Source

#### ConnectionService(ISqlConnectionFactory)

Test constructor that injects dependency interfaces

##### Declaration

    public ConnectionService(ISqlConnectionFactory testFactory)

##### Parameters

Type | Name | Description
--- | --- | ---
ISqlConnectionFactory | testFactory |

### Properties

| Improve this Doc View Source

#### ConnectionFactory

Gets the SQL connection factory instance

##### Declaration

    public ISqlConnectionFactory ConnectionFactory { get; }

##### Property Value

Type | Description
--- | ---
ISqlConnectionFactory |

| Improve this Doc View Source

#### Instance

Gets the singleton service instance

##### Declaration

    public static ConnectionService Instance { get; }

##### Property Value

Type | Description
--- | ---
ConnectionService |

### Methods

| Improve this Doc View Source

#### BuildConnectionString(ConnectionDetails)

Build a connection string from a connection details instance

##### Declaration

    public static string BuildConnectionString(ConnectionDetails connectionDetails)

##### Parameters

Type | Name | Description
--- | --- | ---
ConnectionDetails | connectionDetails |

##### Returns

Type | Description
--- | ---
System.String |

| Improve this Doc View Source

#### CancelConnect(CancelConnectParams)

Cancel a connection that is in the process of opening.

##### Declaration

    public bool CancelConnect(CancelConnectParams cancelParams)

##### Parameters

Type | Name | Description
--- | --- | ---
CancelConnectParams | cancelParams |

##### Returns

Type | Description
--- | ---
System.Boolean |

| Improve this Doc View Source

#### ChangeConnectionDatabaseContext(String, String)

Change the database context of a connection.

##### Declaration

    public void ChangeConnectionDatabaseContext(string ownerUri, string newDatabaseName)

##### Parameters

Type | Name | Description
--- | --- | ---
System.String | ownerUri | URI of the owner of the connection
System.String | newDatabaseName | Name of the database to change the connection to

| Improve this Doc View Source

#### Connect(ConnectParams)

Open a connection with the specified connection details

##### Declaration

    public Task<ConnectionCompleteParams> Connect(ConnectParams connectionParams)

##### Parameters

Type | Name | Description
--- | --- | ---
ConnectParams | connectionParams |

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<ConnectionCompleteParams> |

| Improve this Doc View Source

#### Disconnect(DisconnectParams)

Close a connection with the specified connection details.

##### Declaration

    public bool Disconnect(DisconnectParams disconnectParams)

##### Parameters

Type | Name | Description
--- | --- | ---
DisconnectParams | disconnectParams |

##### Returns

Type | Description
--- | ---
System.Boolean |

| Improve this Doc View Source

#### HandleCancelConnectRequest(CancelConnectParams, RequestContext<Boolean>)

Handle cancel connect requests

##### Declaration

    protected Task HandleCancelConnectRequest(CancelConnectParams cancelParams, RequestContext<bool> requestContext)

##### Parameters

Type | Name | Description
--- | --- | ---
CancelConnectParams | cancelParams |
RequestContext<System.Boolean> | requestContext |

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task |

| Improve this Doc View Source

#### HandleConnectRequest(ConnectParams, RequestContext<Boolean>)

Handle new connection requests

##### Declaration

    protected Task HandleConnectRequest(ConnectParams connectParams, RequestContext<bool> requestContext)

##### Parameters

Type | Name | Description
--- | --- | ---
ConnectParams | connectParams |
RequestContext<System.Boolean> | requestContext |

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task |

| Improve this Doc View Source

#### HandleDidChangeConfigurationNotification(SqlToolsSettings, SqlToolsSettings, EventContext)

##### Declaration

    public Task HandleDidChangeConfigurationNotification(SqlToolsSettings newSettings, SqlToolsSettings oldSettings, EventContext eventContext)

##### Parameters

Type | Name | Description
--- | --- | ---
SqlToolsSettings | newSettings |
SqlToolsSettings | oldSettings |
EventContext | eventContext |

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task |

| Improve this Doc View Source

#### HandleDisconnectRequest(DisconnectParams, RequestContext<Boolean>)

Handle disconnect requests

##### Declaration

    protected Task HandleDisconnectRequest(DisconnectParams disconnectParams, RequestContext<bool> requestContext)

##### Parameters

Type | Name | Description
--- | --- | ---
DisconnectParams | disconnectParams |
RequestContext<System.Boolean> | requestContext |

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task |

| Improve this Doc View Source

#### HandleListDatabasesRequest(ListDatabasesParams, RequestContext<ListDatabasesResponse>)

Handle requests to list databases on the current server

##### Declaration

    protected Task HandleListDatabasesRequest(ListDatabasesParams listDatabasesParams, RequestContext<ListDatabasesResponse> requestContext)

##### Parameters

Type | Name | Description
--- | --- | ---
ListDatabasesParams | listDatabasesParams |
RequestContext<ListDatabasesResponse> | requestContext |

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task |

| Improve this Doc View Source

#### InitializeService(IProtocolEndpoint)

##### Declaration

    public void InitializeService(IProtocolEndpoint serviceHost)

##### Parameters

Type | Name | Description
--- | --- | ---
IProtocolEndpoint | serviceHost |

| Improve this Doc View Source

#### ListDatabases(ListDatabasesParams)

List all databases on the server specified

##### Declaration

    public ListDatabasesResponse ListDatabases(ListDatabasesParams listDatabasesParams)

##### Parameters

Type | Name | Description
--- | --- | ---
ListDatabasesParams | listDatabasesParams |

##### Returns

Type | Description
--- | ---
ListDatabasesResponse |

| Improve this Doc View Source

#### RegisterOnConnectionTask(ConnectionService.OnConnectionHandler)

Add a new method to be called when the onconnection request is submitted

##### Declaration

    public void RegisterOnConnectionTask(ConnectionService.OnConnectionHandler activity)

##### Parameters

Type | Name | Description
--- | --- | ---
ConnectionService.OnConnectionHandler | activity |

| Improve this Doc View Source

#### RegisterOnDisconnectTask(ConnectionService.OnDisconnectHandler)

Add a new method to be called when the ondisconnect request is submitted

##### Declaration

    public void RegisterOnDisconnectTask(ConnectionService.OnDisconnectHandler activity)

##### Parameters

Type | Name | Description
--- | --- | ---
ConnectionService.OnDisconnectHandler | activity |

| Improve this Doc View Source

#### TryFindConnection(String, out ConnectionInfo)

##### Declaration

    public virtual bool TryFindConnection(string ownerUri, out ConnectionInfo connectionInfo)

##### Parameters

Type | Name | Description
--- | --- | ---
System.String | ownerUri |
ConnectionInfo | connectionInfo |

##### Returns

Type | Description
--- | ---
System.Boolean |