Added support for most sql connection string properties
This commit is contained in:
Родитель
e87fb25f4d
Коммит
1f9f6113ca
141
package.json
141
package.json
|
@ -197,30 +197,129 @@
|
|||
"default": "{{put-password-here}}",
|
||||
"description": "[Optional] Password for SQL authentication. If this is empty, you are prompted when you connect."
|
||||
},
|
||||
"connectionTimeout": {
|
||||
"type": "number",
|
||||
"default": 15000,
|
||||
"description": "[Optional] Connection timeout in milliseconds. Default is 30000 ms for Azure SQL DB and 15000 ms otherwise."
|
||||
"authenticationType": {
|
||||
"type": "string",
|
||||
"default": "SqlLogin",
|
||||
"enum": [
|
||||
"Integrated",
|
||||
"SqlLogin"
|
||||
],
|
||||
"description": "[Optional] Specifies the method of authenticating with SQL Server."
|
||||
},
|
||||
"requestTimeout": {
|
||||
"port": {
|
||||
"type": "number",
|
||||
"default": 15000,
|
||||
"description": "[Optional] Request timeout in milliseconds. Default is 30000 ms for Azure SQL DB and 15000 ms otherwise."
|
||||
"default": 1433,
|
||||
"description": "[Optional] Specify the port number to connect to."
|
||||
},
|
||||
"options": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"encrypt": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[Optional] Specify if the connection will be encrypted. Always set to 'true' for Azure SQL DB and loaded from here otherwise."
|
||||
},
|
||||
"appName": {
|
||||
"type": "string",
|
||||
"default": "vscode-mssql",
|
||||
"description": "[Optional] Application name used for SQL server logging (default: 'vscode-mssql')."
|
||||
}
|
||||
}
|
||||
"encrypt": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[Optional] Specify if the connection will be encrypted. Always set to 'true' for Azure SQL DB and loaded from here otherwise."
|
||||
},
|
||||
"trustServerCertificate": {
|
||||
"type": "boolean",
|
||||
"description": "[Optional]"
|
||||
},
|
||||
"persistSecurityInfo": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[Optional]"
|
||||
},
|
||||
"connectTimeout": {
|
||||
"type": "number",
|
||||
"default": 15,
|
||||
"description": "[Optional] The length of time in seconds to wait for a connection to the server before terminating the attempt and generating error."
|
||||
},
|
||||
"connectRetryCount": {
|
||||
"type": "number",
|
||||
"default": 1,
|
||||
"description": "[Optional] Number of attempts to restore connection."
|
||||
},
|
||||
"connectRetryInterval": {
|
||||
"type": "number",
|
||||
"default": 10,
|
||||
"description": "[Optional] Delay between attempts to restore connection."
|
||||
},
|
||||
"applicationName": {
|
||||
"type": "string",
|
||||
"default": "vscode-mssql",
|
||||
"description": "[Optional] Application name used for SQL server logging (default: 'vscode-mssql')."
|
||||
},
|
||||
"workstationId": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"description": "[Optional] The name of the workstation connecting to SQL Server."
|
||||
},
|
||||
"applicationIntent": {
|
||||
"type": "string",
|
||||
"default": "ReadWrite",
|
||||
"enum": [
|
||||
"ReadWrite",
|
||||
"ReadOnly"
|
||||
],
|
||||
"description": "[Optional]"
|
||||
},
|
||||
"currentLanguage": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"description": "[Optional]"
|
||||
},
|
||||
"pooling": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[Optional]"
|
||||
},
|
||||
"maxPoolSize": {
|
||||
"type": "number",
|
||||
"default": 100,
|
||||
"description": "[Optional]"
|
||||
},
|
||||
"minPoolSize": {
|
||||
"type": "number",
|
||||
"default": 0,
|
||||
"description": "[Optional]"
|
||||
},
|
||||
"loadBalanceTimeout": {
|
||||
"type": "number",
|
||||
"default": 0,
|
||||
"description": "[Optional]"
|
||||
},
|
||||
"replication": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "[Optional]"
|
||||
},
|
||||
"attachDbFilename": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"description": "[Optional]"
|
||||
},
|
||||
"failoverPartner": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"description": "[Optional]"
|
||||
},
|
||||
"multiSubnetFailover": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "[Optional]"
|
||||
},
|
||||
"multipleActiveResultSets": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "[Optional]"
|
||||
},
|
||||
"packetSize": {
|
||||
"type": "number",
|
||||
"default": 8192,
|
||||
"description": "[Optional]"
|
||||
},
|
||||
"typeSystemVersion": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"Latest"
|
||||
],
|
||||
"description": "[Optional]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
'use strict';
|
||||
import vscode = require('vscode');
|
||||
import { ConnectionCredentials } from '../models/connectionCredentials';
|
||||
import Constants = require('../models/constants');
|
||||
import * as Contracts from '../models/contracts';
|
||||
import Utils = require('../models/utils');
|
||||
|
@ -196,12 +197,7 @@ export default class ConnectionManager {
|
|||
self.statusView.connecting(fileUri, connectionCreds);
|
||||
|
||||
// package connection details for request message
|
||||
let connectionDetails = new Contracts.ConnectionDetails();
|
||||
connectionDetails.userName = connectionCreds.user;
|
||||
connectionDetails.password = connectionCreds.password;
|
||||
connectionDetails.serverName = connectionCreds.server;
|
||||
connectionDetails.databaseName = connectionCreds.database;
|
||||
|
||||
const connectionDetails = ConnectionCredentials.createConnectionDetails(connectionCreds);
|
||||
let connectParams = new Contracts.ConnectParams();
|
||||
connectParams.ownerUri = fileUri;
|
||||
connectParams.connection = connectionDetails;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
'use strict';
|
||||
import Constants = require('./constants');
|
||||
import { ConnectionDetails } from './contracts';
|
||||
import { IConnectionCredentials, AuthenticationTypes } from './interfaces';
|
||||
import * as utils from './utils';
|
||||
import { QuestionTypes, IQuestion, IPrompter, INameValueChoice } from '../prompts/question';
|
||||
|
@ -10,12 +11,72 @@ import os = require('os');
|
|||
export class ConnectionCredentials implements IConnectionCredentials {
|
||||
public server: string;
|
||||
public database: string;
|
||||
public authenticationType: string;
|
||||
public user: string;
|
||||
public password: string;
|
||||
public connectionTimeout: number;
|
||||
public requestTimeout: number;
|
||||
public options: { encrypt: boolean, appName: string };
|
||||
|
||||
public port: number;
|
||||
|
||||
public authenticationType: string;
|
||||
public encrypt: boolean;
|
||||
public trustServerCertificate: boolean;
|
||||
public persistSecurityInfo: boolean;
|
||||
public connectTimeout: number;
|
||||
public connectRetryCount: number;
|
||||
public connectRetryInterval: number;
|
||||
public applicationName: string;
|
||||
public workstationId: string;
|
||||
public applicationIntent: string;
|
||||
public currentLanguage: string;
|
||||
public pooling: boolean;
|
||||
public maxPoolSize: number;
|
||||
public minPoolSize: number;
|
||||
public loadBalanceTimeout: number;
|
||||
public replication: boolean;
|
||||
public attachDbFilename: string;
|
||||
public failoverPartner: string;
|
||||
public multiSubnetFailover: boolean;
|
||||
public multipleActiveResultSets: boolean;
|
||||
public packetSize: number;
|
||||
public typeSystemVersion: string;
|
||||
|
||||
/**
|
||||
* Create a connection details contract from connection credentials.
|
||||
*/
|
||||
public static createConnectionDetails(credentials: IConnectionCredentials): ConnectionDetails {
|
||||
let details: ConnectionDetails = new ConnectionDetails();
|
||||
details.serverName = credentials.server;
|
||||
if (credentials.port && details.serverName.indexOf(',') === -1) {
|
||||
// Port is appended to the server name in a connection string
|
||||
details.serverName += (',' + credentials.port);
|
||||
}
|
||||
details.databaseName = credentials.database;
|
||||
details.userName = credentials.user;
|
||||
details.password = credentials.password;
|
||||
details.authenticationType = credentials.authenticationType;
|
||||
details.encrypt = credentials.encrypt;
|
||||
details.trustServerCertificate = credentials.trustServerCertificate;
|
||||
details.persistSecurityInfo = credentials.persistSecurityInfo;
|
||||
details.connectTimeout = credentials.connectTimeout;
|
||||
details.connectRetryCount = credentials.connectRetryCount;
|
||||
details.connectRetryInterval = credentials.connectRetryInterval;
|
||||
details.applicationName = credentials.applicationName;
|
||||
details.workstationId = credentials.workstationId;
|
||||
details.applicationIntent = credentials.applicationIntent;
|
||||
details.currentLanguage = credentials.currentLanguage;
|
||||
details.pooling = credentials.pooling;
|
||||
details.maxPoolSize = credentials.maxPoolSize;
|
||||
details.minPoolSize = credentials.minPoolSize;
|
||||
details.loadBalanceTimeout = credentials.loadBalanceTimeout;
|
||||
details.replication = credentials.replication;
|
||||
details.attachDbFilename = credentials.attachDbFilename;
|
||||
details.failoverPartner = credentials.failoverPartner;
|
||||
details.multiSubnetFailover = credentials.multiSubnetFailover;
|
||||
details.multipleActiveResultSets = credentials.multipleActiveResultSets;
|
||||
details.packetSize = credentials.packetSize;
|
||||
details.typeSystemVersion = credentials.typeSystemVersion;
|
||||
|
||||
return details;
|
||||
}
|
||||
|
||||
public static ensureRequiredPropertiesSet(
|
||||
credentials: IConnectionCredentials,
|
||||
|
|
|
@ -20,41 +20,27 @@ export function fixupConnectionCredentials(connCreds: Interfaces.IConnectionCred
|
|||
connCreds.password = '';
|
||||
}
|
||||
|
||||
if (!connCreds.connectionTimeout) {
|
||||
connCreds.connectionTimeout = Constants.defaultConnectionTimeout;
|
||||
}
|
||||
|
||||
if (!connCreds.requestTimeout) {
|
||||
connCreds.requestTimeout = Constants.defaultRequestTimeout;
|
||||
}
|
||||
|
||||
// default values for advanced options
|
||||
if (!connCreds.options) {
|
||||
connCreds.options = {encrypt: false, appName: Constants.extensionName};
|
||||
if (!connCreds.connectTimeout) {
|
||||
connCreds.connectTimeout = Constants.defaultConnectionTimeout;
|
||||
}
|
||||
|
||||
// default value for encrypt
|
||||
if (!connCreds.options.encrypt) {
|
||||
connCreds.options.encrypt = false;
|
||||
if (!connCreds.encrypt) {
|
||||
connCreds.encrypt = false;
|
||||
}
|
||||
|
||||
// default value for appName
|
||||
if (!connCreds.options.appName) {
|
||||
connCreds.options.appName = Constants.extensionName;
|
||||
if (!connCreds.applicationName) {
|
||||
connCreds.applicationName = Constants.extensionName;
|
||||
}
|
||||
|
||||
if (isAzureDatabase(connCreds.server)) {
|
||||
// always encrypt connection if connecting to Azure SQL
|
||||
connCreds.options.encrypt = true;
|
||||
connCreds.encrypt = true;
|
||||
|
||||
// Ensure minumum connection timeout if connecting to Azure SQL
|
||||
if (connCreds.connectionTimeout < Constants.azureSqlDbConnectionTimeout) {
|
||||
connCreds.connectionTimeout = Constants.azureSqlDbConnectionTimeout;
|
||||
}
|
||||
|
||||
// Ensure minumum request timeout if connecting to Azure SQL
|
||||
if (connCreds.requestTimeout < Constants.azureSqlDbRequestTimeout) {
|
||||
connCreds.requestTimeout = Constants.azureSqlDbRequestTimeout;
|
||||
if (connCreds.connectTimeout < Constants.azureSqlDbConnectionTimeout) {
|
||||
connCreds.connectTimeout = Constants.azureSqlDbConnectionTimeout;
|
||||
}
|
||||
}
|
||||
return connCreds;
|
||||
|
@ -65,13 +51,13 @@ function isAzureDatabase(server: string): boolean {
|
|||
return (server ? server.endsWith(Constants.sqlDbPrefix) : false);
|
||||
}
|
||||
|
||||
// TODO: this doesn't appear to be used anywhere in the project. Do we need it?
|
||||
export function dump(connCreds: Interfaces.IConnectionCredentials): string {
|
||||
let contents = 'server=' + (connCreds.server ? connCreds.server : 'null') +
|
||||
' | database=' + (connCreds.database ? connCreds.database : 'null') +
|
||||
' | username=' + (connCreds.user ? connCreds.user : 'null') +
|
||||
' | encrypt=' + connCreds.options.encrypt +
|
||||
' | connectionTimeout=' + connCreds.connectionTimeout +
|
||||
' | connectionTimeout=' + connCreds.requestTimeout;
|
||||
' | encrypt=' + connCreds.encrypt +
|
||||
' | connectionTimeout=' + connCreds.connectTimeout;
|
||||
return contents;
|
||||
}
|
||||
|
||||
|
@ -80,9 +66,29 @@ export function equals(connCreds: Interfaces.IConnectionCredentials, theOther: I
|
|||
let equal = (connCreds.server === theOther.server) &&
|
||||
(connCreds.database === theOther.database) &&
|
||||
(connCreds.user === theOther.user) &&
|
||||
(connCreds.options.encrypt === theOther.options.encrypt) &&
|
||||
(connCreds.connectionTimeout === theOther.connectionTimeout) &&
|
||||
(connCreds.requestTimeout === theOther.requestTimeout);
|
||||
(connCreds.encrypt === theOther.encrypt) &&
|
||||
(connCreds.connectTimeout === theOther.connectTimeout) &&
|
||||
(connCreds.applicationIntent === theOther.applicationIntent) &&
|
||||
(connCreds.applicationName === theOther.applicationName) &&
|
||||
(connCreds.attachDbFilename === theOther.attachDbFilename) &&
|
||||
(connCreds.authenticationType === theOther.authenticationType) &&
|
||||
(connCreds.connectRetryCount === theOther.connectRetryCount) &&
|
||||
(connCreds.connectRetryInterval === theOther.connectRetryInterval) &&
|
||||
(connCreds.currentLanguage === theOther.currentLanguage) &&
|
||||
(connCreds.failoverPartner === theOther.failoverPartner) &&
|
||||
(connCreds.loadBalanceTimeout === theOther.loadBalanceTimeout) &&
|
||||
(connCreds.maxPoolSize === theOther.maxPoolSize) &&
|
||||
(connCreds.minPoolSize === theOther.minPoolSize) &&
|
||||
(connCreds.multipleActiveResultSets === theOther.multipleActiveResultSets) &&
|
||||
(connCreds.multiSubnetFailover === theOther.multiSubnetFailover) &&
|
||||
(connCreds.packetSize === theOther.packetSize) &&
|
||||
(connCreds.persistSecurityInfo === theOther.persistSecurityInfo) &&
|
||||
(connCreds.pooling === theOther.pooling) &&
|
||||
(connCreds.port === theOther.port) &&
|
||||
(connCreds.replication === theOther.replication) &&
|
||||
(connCreds.trustServerCertificate === theOther.trustServerCertificate) &&
|
||||
(connCreds.typeSystemVersion === theOther.typeSystemVersion) &&
|
||||
(connCreds.workstationId === theOther.workstationId);
|
||||
return equal;
|
||||
}
|
||||
|
||||
|
@ -99,18 +105,52 @@ export function getPicklistDescription(connCreds: Interfaces.IConnectionCredenti
|
|||
|
||||
export function getPicklistDetails(connCreds: Interfaces.IConnectionCredentials): string {
|
||||
return '[' +
|
||||
'encrypt connection: ' + (connCreds.options.encrypt ? 'true' : 'false') +
|
||||
', connection timeout: ' + connCreds.connectionTimeout + ' ms' +
|
||||
', request timeout: ' + connCreds.requestTimeout + ' ms' +
|
||||
'encrypt connection: ' + (connCreds.encrypt ? 'true' : 'false') +
|
||||
', port: ' + (connCreds.port ? connCreds.port : Constants.defaultPortNumber) +
|
||||
', connection timeout: ' + connCreds.connectTimeout + ' s' +
|
||||
']';
|
||||
}
|
||||
|
||||
function addTooltipItem(creds: Interfaces.IConnectionCredentials, property: string): string {
|
||||
let value: any = creds[property];
|
||||
if (typeof value === 'undefined') {
|
||||
return '';
|
||||
} else if (typeof value === 'boolean') {
|
||||
return property + ': ' + (value ? 'true' : 'false') + '\r\n';
|
||||
} else {
|
||||
return property + ': ' + value + '\r\n';
|
||||
}
|
||||
}
|
||||
|
||||
export function getTooltip(connCreds: Interfaces.IConnectionCredentials): string {
|
||||
return 'server: ' + connCreds.server + '\r\n' +
|
||||
let tooltip: string =
|
||||
'server: ' + connCreds.server + '\r\n' +
|
||||
'database: ' + (connCreds.database ? connCreds.database : '<connection default>') + '\r\n' +
|
||||
'username: ' + connCreds.user + '\r\n' +
|
||||
'encrypt connection: ' + (connCreds.options.encrypt ? 'true' : 'false') + '\r\n' +
|
||||
'connection timeout: ' + connCreds.connectionTimeout + ' ms\r\n' +
|
||||
'request timeout: ' + connCreds.requestTimeout + ' ms\r\n' +
|
||||
'appName: ' + connCreds.options.appName;
|
||||
'encrypt connection: ' + (connCreds.encrypt ? 'true' : 'false') + '\r\n' +
|
||||
'connection timeout: ' + connCreds.connectTimeout + ' s\r\n';
|
||||
|
||||
tooltip += addTooltipItem(connCreds, 'port');
|
||||
tooltip += addTooltipItem(connCreds, 'applicationName');
|
||||
tooltip += addTooltipItem(connCreds, 'applicationIntent');
|
||||
tooltip += addTooltipItem(connCreds, 'attachDbFilename');
|
||||
tooltip += addTooltipItem(connCreds, 'authenticationType');
|
||||
tooltip += addTooltipItem(connCreds, 'connectRetryCount');
|
||||
tooltip += addTooltipItem(connCreds, 'connectRetryInterval');
|
||||
tooltip += addTooltipItem(connCreds, 'currentLanguage');
|
||||
tooltip += addTooltipItem(connCreds, 'failoverPartner');
|
||||
tooltip += addTooltipItem(connCreds, 'loadBalanceTimeout');
|
||||
tooltip += addTooltipItem(connCreds, 'maxPoolSize');
|
||||
tooltip += addTooltipItem(connCreds, 'minPoolSize');
|
||||
tooltip += addTooltipItem(connCreds, 'multipleActiveResultSets');
|
||||
tooltip += addTooltipItem(connCreds, 'multiSubnetFailover');
|
||||
tooltip += addTooltipItem(connCreds, 'packetSize');
|
||||
tooltip += addTooltipItem(connCreds, 'persistSecurityInfo');
|
||||
tooltip += addTooltipItem(connCreds, 'pooling');
|
||||
tooltip += addTooltipItem(connCreds, 'replication');
|
||||
tooltip += addTooltipItem(connCreds, 'trustServerCertificate');
|
||||
tooltip += addTooltipItem(connCreds, 'typeSystemVersion');
|
||||
tooltip += addTooltipItem(connCreds, 'workstationId');
|
||||
|
||||
return tooltip;
|
||||
}
|
||||
|
|
|
@ -11,11 +11,10 @@ export const cmdRemoveProfile = 'extension.removeprofile';
|
|||
export const cmdChooseDatabase = 'extension.chooseDatabase';
|
||||
|
||||
export const sqlDbPrefix = '.database.windows.net';
|
||||
export const defaultConnectionTimeout = 15000;
|
||||
export const defaultRequestTimeout = 15000;
|
||||
export const azureSqlDbConnectionTimeout = 30000;
|
||||
export const azureSqlDbRequestTimeout = 30000;
|
||||
export const defaultConnectionTimeout = 15;
|
||||
export const azureSqlDbConnectionTimeout = 30;
|
||||
export const azureDatabase = 'Azure';
|
||||
export const defaultPortNumber = 1433;
|
||||
|
||||
export const outputContentTypeRoot = 'root';
|
||||
export const outputContentTypeMessages = 'messages';
|
||||
|
|
|
@ -7,19 +7,142 @@ export namespace ConnectionRequest {
|
|||
export const type: RequestType<ConnectParams, ConnectionResult, void> = { get method(): string { return 'connection/connect'; } };
|
||||
}
|
||||
|
||||
// Required parameters to initialize a connection to a database
|
||||
/**
|
||||
* Parameters to initialize a connection to a database
|
||||
*/
|
||||
export class ConnectionDetails {
|
||||
// server name
|
||||
/**
|
||||
* server name
|
||||
*/
|
||||
public serverName: string;
|
||||
|
||||
// database name
|
||||
/**
|
||||
* database name
|
||||
*/
|
||||
public databaseName: string;
|
||||
|
||||
// user name
|
||||
/**
|
||||
* user name
|
||||
*/
|
||||
public userName: string;
|
||||
|
||||
// unencrypted password
|
||||
/**
|
||||
* unencrypted password
|
||||
*/
|
||||
public password: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the authentication to use.
|
||||
*/
|
||||
public authenticationType: string;
|
||||
|
||||
/**
|
||||
* Gets or sets a Boolean value that indicates whether SQL Server uses SSL encryption for all data sent between the client and server if
|
||||
* the server has a certificate installed.
|
||||
*/
|
||||
public encrypt: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets a value that indicates whether the channel will be encrypted while bypassing walking the certificate chain to validate trust.
|
||||
*/
|
||||
public trustServerCertificate: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets a Boolean value that indicates if security-sensitive information, such as the password, is not returned as part of the
|
||||
* connection if the connection is open or has ever been in an open state.
|
||||
*/
|
||||
public persistSecurityInfo: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets the length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error.
|
||||
*/
|
||||
public connectTimeout: number;
|
||||
|
||||
/**
|
||||
* The number of reconnections attempted after identifying that there was an idle connection failure.
|
||||
*/
|
||||
public connectRetryCount: number;
|
||||
|
||||
/**
|
||||
* Amount of time (in seconds) between each reconnection attempt after identifying that there was an idle connection failure.
|
||||
*/
|
||||
public connectRetryInterval: number;
|
||||
|
||||
/**
|
||||
* Gets or sets the name of the application associated with the connection string.
|
||||
*/
|
||||
public applicationName: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the name of the workstation connecting to SQL Server.
|
||||
*/
|
||||
public workstationId: string;
|
||||
|
||||
/**
|
||||
* Declares the application workload type when connecting to a database in an SQL Server Availability Group.
|
||||
*/
|
||||
public applicationIntent: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the SQL Server Language record name.
|
||||
*/
|
||||
public currentLanguage: string;
|
||||
|
||||
/**
|
||||
* Gets or sets a Boolean value that indicates whether the connection will be pooled or explicitly opened every time that the connection is requested.
|
||||
*/
|
||||
public pooling: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets the maximum number of connections allowed in the connection pool for this specific connection string.
|
||||
*/
|
||||
public maxPoolSize: number;
|
||||
|
||||
/**
|
||||
* Gets or sets the minimum number of connections allowed in the connection pool for this specific connection string.
|
||||
*/
|
||||
public minPoolSize: number;
|
||||
|
||||
/**
|
||||
* Gets or sets the minimum time, in seconds, for the connection to live in the connection pool before being destroyed.
|
||||
*/
|
||||
public loadBalanceTimeout: number;
|
||||
|
||||
/**
|
||||
* Gets or sets a Boolean value that indicates whether replication is supported using the connection.
|
||||
*/
|
||||
public replication: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets a string that contains the name of the primary data file. This includes the full path name of an attachable database.
|
||||
*/
|
||||
public attachDbFilename: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the name or address of the partner server to connect to if the primary server is down.
|
||||
*/
|
||||
public failoverPartner: string;
|
||||
|
||||
/**
|
||||
* If your application is connecting to an AlwaysOn availability group (AG) on different subnets, setting MultiSubnetFailover=true provides
|
||||
* faster detection of and connection to the (currently) active server.
|
||||
*/
|
||||
public multiSubnetFailover: boolean;
|
||||
|
||||
/**
|
||||
* When true, an application can maintain multiple active result sets (MARS).
|
||||
*/
|
||||
public multipleActiveResultSets: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets the size in bytes of the network packets used to communicate with an instance of SQL Server.
|
||||
*/
|
||||
public packetSize: number;
|
||||
|
||||
/**
|
||||
* Gets or sets a string value that indicates the type system the application expects.
|
||||
*/
|
||||
public typeSystemVersion: string;
|
||||
}
|
||||
|
||||
// Connection request message format
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
'use strict';
|
||||
import vscode = require('vscode');
|
||||
import Constants = require('./constants');
|
||||
/*
|
||||
import * as Contracts from './contracts';
|
||||
*/
|
||||
|
||||
// interfaces
|
||||
export enum ContentType {
|
||||
|
@ -21,19 +24,148 @@ export enum AuthenticationTypes {
|
|||
export const ContentTypes = [Constants.outputContentTypeRoot, Constants.outputContentTypeMessages, Constants.outputContentTypeResultsetMeta,
|
||||
Constants.outputContentTypeColumns, Constants.outputContentTypeRows];
|
||||
|
||||
// mssql.config wrapped into an interface for us to use more easily
|
||||
// Provided by the user when creating a new database connection
|
||||
// See this for more info: http://pekim.github.io/tedious/api-connection.html
|
||||
/**
|
||||
* Interface exposed to the user for creating new database connections.
|
||||
*/
|
||||
export interface IConnectionCredentials {
|
||||
/**
|
||||
* server name
|
||||
*/
|
||||
server: string;
|
||||
|
||||
/**
|
||||
* database name
|
||||
*/
|
||||
database: string;
|
||||
authenticationType: string;
|
||||
|
||||
/**
|
||||
* user name
|
||||
*/
|
||||
user: string;
|
||||
|
||||
/**
|
||||
* password
|
||||
*/
|
||||
password: string;
|
||||
connectionTimeout: number;
|
||||
requestTimeout: number;
|
||||
options: { encrypt: boolean, appName: string };
|
||||
};
|
||||
|
||||
/**
|
||||
* The port number to connect to.
|
||||
*/
|
||||
port: number;
|
||||
|
||||
/**
|
||||
* Gets or sets the authentication to use.
|
||||
*/
|
||||
authenticationType: string;
|
||||
|
||||
/**
|
||||
* Gets or sets a Boolean value that indicates whether SQL Server uses SSL encryption for all data sent between the client and server if
|
||||
* the server has a certificate installed.
|
||||
*/
|
||||
encrypt: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets a value that indicates whether the channel will be encrypted while bypassing walking the certificate chain to validate trust.
|
||||
*/
|
||||
trustServerCertificate: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets a Boolean value that indicates if security-sensitive information, such as the password, is not returned as part of the connection
|
||||
* if the connection is open or has ever been in an open state.
|
||||
*/
|
||||
persistSecurityInfo: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets the length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error.
|
||||
*/
|
||||
connectTimeout: number;
|
||||
|
||||
/**
|
||||
* The number of reconnections attempted after identifying that there was an idle connection failure.
|
||||
*/
|
||||
connectRetryCount: number;
|
||||
|
||||
/**
|
||||
* Amount of time (in seconds) between each reconnection attempt after identifying that there was an idle connection failure.
|
||||
*/
|
||||
connectRetryInterval: number;
|
||||
|
||||
/**
|
||||
* Gets or sets the name of the application associated with the connection string.
|
||||
*/
|
||||
applicationName: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the name of the workstation connecting to SQL Server.
|
||||
*/
|
||||
workstationId: string;
|
||||
|
||||
/**
|
||||
* Declares the application workload type when connecting to a database in an SQL Server Availability Group.
|
||||
*/
|
||||
applicationIntent: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the SQL Server Language record name.
|
||||
*/
|
||||
currentLanguage: string;
|
||||
|
||||
/**
|
||||
* Gets or sets a Boolean value that indicates whether the connection will be pooled or explicitly opened every time that the connection is requested.
|
||||
*/
|
||||
pooling: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets the maximum number of connections allowed in the connection pool for this specific connection string.
|
||||
*/
|
||||
maxPoolSize: number;
|
||||
|
||||
/**
|
||||
* Gets or sets the minimum number of connections allowed in the connection pool for this specific connection string.
|
||||
*/
|
||||
minPoolSize: number;
|
||||
|
||||
/**
|
||||
* Gets or sets the minimum time, in seconds, for the connection to live in the connection pool before being destroyed.
|
||||
*/
|
||||
loadBalanceTimeout: number;
|
||||
|
||||
/**
|
||||
* Gets or sets a Boolean value that indicates whether replication is supported using the connection.
|
||||
*/
|
||||
replication: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets a string that contains the name of the primary data file. This includes the full path name of an attachable database.
|
||||
*/
|
||||
attachDbFilename: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the name or address of the partner server to connect to if the primary server is down.
|
||||
*/
|
||||
failoverPartner: string;
|
||||
|
||||
/**
|
||||
* If your application is connecting to an AlwaysOn availability group (AG) on different subnets, setting MultiSubnetFailover=true
|
||||
* provides faster detection of and connection to the (currently) active server.
|
||||
*/
|
||||
multiSubnetFailover: boolean;
|
||||
|
||||
/**
|
||||
* When true, an application can maintain multiple active result sets (MARS).
|
||||
*/
|
||||
multipleActiveResultSets: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets the size in bytes of the network packets used to communicate with an instance of SQL Server.
|
||||
*/
|
||||
packetSize: number;
|
||||
|
||||
/**
|
||||
* Gets or sets a string value that indicates the type system the application expects.
|
||||
*/
|
||||
typeSystemVersion: string;
|
||||
}
|
||||
|
||||
// A Connection Profile contains all the properties of connection credentials, with additional
|
||||
// optional name and details on whether password should be saved
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import * as TypeMoq from 'typemoq';
|
||||
import { IConnectionProfile } from '../src/models/interfaces';
|
||||
import { IConnectionCredentials, IConnectionProfile } from '../src/models/interfaces';
|
||||
import { ConnectionCredentials } from '../src/models/ConnectionCredentials';
|
||||
import { ConnectionProfile } from '../src/models/ConnectionProfile';
|
||||
import { IQuestion, IPrompter, INameValueChoice } from '../src/prompts/question';
|
||||
import TestPrompter from './TestPrompter';
|
||||
|
@ -8,6 +9,39 @@ import Constants = require('../src/models/constants');
|
|||
import assert = require('assert');
|
||||
import os = require('os');
|
||||
|
||||
function createTestCredentials(): IConnectionCredentials {
|
||||
const creds: IConnectionCredentials = {
|
||||
server: 'my-server',
|
||||
database: 'my_db',
|
||||
user: 'sa',
|
||||
password: '12345678',
|
||||
port: 1234,
|
||||
authenticationType: 'SQL Authentication',
|
||||
encrypt: false,
|
||||
trustServerCertificate: false,
|
||||
persistSecurityInfo: false,
|
||||
connectTimeout: 15,
|
||||
connectRetryCount: 0,
|
||||
connectRetryInterval: 0,
|
||||
applicationName: 'vscode-mssql',
|
||||
workstationId: 'test',
|
||||
applicationIntent: '',
|
||||
currentLanguage: '',
|
||||
pooling: true,
|
||||
maxPoolSize: 15,
|
||||
minPoolSize: 0,
|
||||
loadBalanceTimeout: 0,
|
||||
replication: false,
|
||||
attachDbFilename: '',
|
||||
failoverPartner: '',
|
||||
multiSubnetFailover: false,
|
||||
multipleActiveResultSets: false,
|
||||
packetSize: 8192,
|
||||
typeSystemVersion: 'Latest'
|
||||
};
|
||||
return creds;
|
||||
}
|
||||
|
||||
suite('Connection Profile tests', () => {
|
||||
let authTypeQuestionIndex = 2;
|
||||
|
||||
|
@ -123,6 +157,49 @@ suite('Connection Profile tests', () => {
|
|||
|
||||
});
|
||||
|
||||
test('Port number is applied to server name when connection credentials are transformed into details', () => {
|
||||
// Given a connection credentials object with server and a port
|
||||
let creds = new ConnectionCredentials();
|
||||
creds.server = 'my-server';
|
||||
creds.port = 1234;
|
||||
|
||||
// When credentials are transformed into a details contract
|
||||
const details = ConnectionCredentials.createConnectionDetails(creds);
|
||||
|
||||
// Server name should be in the format <address>,<port>
|
||||
assert.strictEqual(details.serverName, 'my-server,1234');
|
||||
});
|
||||
|
||||
test('All connection details properties can be set from connection credentials', () => {
|
||||
const creds = createTestCredentials();
|
||||
const details = ConnectionCredentials.createConnectionDetails(creds);
|
||||
|
||||
assert.notStrictEqual(typeof details.applicationIntent, 'undefined');
|
||||
assert.notStrictEqual(typeof details.applicationName, 'undefined');
|
||||
assert.notStrictEqual(typeof details.attachDbFilename, 'undefined');
|
||||
assert.notStrictEqual(typeof details.authenticationType, 'undefined');
|
||||
assert.notStrictEqual(typeof details.connectRetryCount, 'undefined');
|
||||
assert.notStrictEqual(typeof details.connectRetryInterval, 'undefined');
|
||||
assert.notStrictEqual(typeof details.connectTimeout, 'undefined');
|
||||
assert.notStrictEqual(typeof details.currentLanguage, 'undefined');
|
||||
assert.notStrictEqual(typeof details.databaseName, 'undefined');
|
||||
assert.notStrictEqual(typeof details.encrypt, 'undefined');
|
||||
assert.notStrictEqual(typeof details.failoverPartner, 'undefined');
|
||||
assert.notStrictEqual(typeof details.loadBalanceTimeout, 'undefined');
|
||||
assert.notStrictEqual(typeof details.maxPoolSize, 'undefined');
|
||||
assert.notStrictEqual(typeof details.minPoolSize, 'undefined');
|
||||
assert.notStrictEqual(typeof details.multipleActiveResultSets, 'undefined');
|
||||
assert.notStrictEqual(typeof details.multiSubnetFailover, 'undefined');
|
||||
assert.notStrictEqual(typeof details.packetSize, 'undefined');
|
||||
assert.notStrictEqual(typeof details.password, 'undefined');
|
||||
assert.notStrictEqual(typeof details.persistSecurityInfo, 'undefined');
|
||||
assert.notStrictEqual(typeof details.pooling, 'undefined');
|
||||
assert.notStrictEqual(typeof details.replication, 'undefined');
|
||||
assert.notStrictEqual(typeof details.serverName, 'undefined');
|
||||
assert.notStrictEqual(typeof details.trustServerCertificate, 'undefined');
|
||||
assert.notStrictEqual(typeof details.typeSystemVersion, 'undefined');
|
||||
assert.notStrictEqual(typeof details.userName, 'undefined');
|
||||
assert.notStrictEqual(typeof details.workstationId, 'undefined');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -47,14 +47,33 @@ function createTestConnectionResult(): Contracts.ConnectionResult {
|
|||
|
||||
function createTestCredentials(): IConnectionCredentials {
|
||||
const creds: IConnectionCredentials = {
|
||||
server: 'my-server',
|
||||
database: 'my_db',
|
||||
authenticationType: 'SQL Authentication',
|
||||
user: 'sa',
|
||||
password: '12345678',
|
||||
connectionTimeout: 30000,
|
||||
requestTimeout: 30000,
|
||||
options: { encrypt: false, appName: 'vscode-mssql' }
|
||||
server: 'my-server',
|
||||
database: 'my_db',
|
||||
user: 'sa',
|
||||
password: '12345678',
|
||||
port: 1234,
|
||||
authenticationType: 'SQL Authentication',
|
||||
encrypt: false,
|
||||
trustServerCertificate: false,
|
||||
persistSecurityInfo: false,
|
||||
connectTimeout: 15,
|
||||
connectRetryCount: 0,
|
||||
connectRetryInterval: 0,
|
||||
applicationName: 'vscode-mssql',
|
||||
workstationId: 'test',
|
||||
applicationIntent: '',
|
||||
currentLanguage: '',
|
||||
pooling: true,
|
||||
maxPoolSize: 15,
|
||||
minPoolSize: 0,
|
||||
loadBalanceTimeout: 0,
|
||||
replication: false,
|
||||
attachDbFilename: '',
|
||||
failoverPartner: '',
|
||||
multiSubnetFailover: false,
|
||||
multipleActiveResultSets: false,
|
||||
packetSize: 8192,
|
||||
typeSystemVersion: 'Latest'
|
||||
};
|
||||
return creds;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче